Finding a VM with a Particular MAC Address
One of my customers was recently troubleshooting a network issue and had tracked it down to a single VMware MAC Address. They tasked me with finding that VM that had that MAC address assigned, which is not a simple process through the GUI. Fortunately, it's a very easy problem to solve with a script, and so PowerCLI to the rescue.
All that I did with this script was get all of the VMs from vCenter, then loop through each one getting all of their NICs. I then compared the MAC of that NIC against the MAC that the customer had identified, and we very swiftly had identified the problem VM.
All that I did with this script was get all of the VMs from vCenter, then loop through each one getting all of their NICs. I then compared the MAC of that NIC against the MAC that the customer had identified, and we very swiftly had identified the problem VM.
$MacOfInterest = "00:50:56:7b:00:00"
$allVMs = Get-VM
foreach ($thisVM in $allVMs)
{
foreach ($thisAdapter in ($thisVM | Get-NetworkAdapter))
{
if ($thisAdapter.MacAddress -eq $MacOfInterest)
{
echo $thisVM.name
}
}
}
Comments
Post a Comment
Sorry guys, I've been getting a lot of spam recently, so I've had to turn on comment moderation. I'll do my best to moderate them swiftly after they're submitted,