Finding a VM by MAC address

Sometimes you only have a MAC address.   Whether you are starting from a DHCP log, or DNS entry, or some other source, occasionally you have less info than you would like.  If you find yourself with only a MAC address and a bunch of VMs to dig through then PowerCLI can help you find the machine you want.  It might also give you some tools to audit your environment and make sure everything is actually exactly as you expect it to be.

Once in PowerCLI and connected to VCenter a simple command will list all Network Adapters in our vCenter

Get-NetworkAdapter -VM *

It is then just a matter of filtering this output to match the MAC address we have:

Get-NetworkAdapter -VM * | Where {$_.MacAddress -eq "00:50:56:B2:2E:D9"}

Now that you have the adapter for the Virtual machine you want you can get the VM you want by expanding the parent attribute:

Get-NetworkAdapter -VM * | Where {$_.MacAddress -eq "00:50:56:B2:2E:D9"} | SELECT -expand parent | FT *

You now have all the attributes of the parent machine you could want, maybe just select Name, Host, and notes to narrow it down so you can get right to your target machine.

Get-NetworkAdapter -VM * | Where {$_.MacAddress -eq "00:50:56:B2:2E:D9"} | SELECT -expand parent | SELECT name, vmhost, notes

As a bonus, when using this method we can switch the where clause out and hunt for partial MAC addresses:

Get-NetworkAdapter -VM * | Where {$_.MacAddress -like "00:50:56:B2:*:D9"} | SELECT -expand parent | SELECT name, vmhost, notes

or if you want to find the IP address of the host you can use Get-VMGuest

Get-NetworkAdapter -VM * | Where {$_.MacAddress -like "00:50:56:B2:*:D9"} | SELECT -expand parent | Get-VMGuest

I hope this helps someone else in their time of night hunting down a rouge machine(s) 🙂




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s