How to find virtual machine name from a MAC address using PowerShell

Stating the obvious:
1. you need vCenter server
2. you need to be connected to your VC server from PowerShell

To get the VM name from MAC address just run this command
get-vm | Get-NetworkAdapter | where {$_.macaddress -eq "00:50:56:b4:3d:12"} | select parent,macaddress

or save this as a script i.e. get-VMfromMAC.ps1
$mac = Read-Host "What mac address do you want to lookup (format:11:22:33:44:55:66 )"
get-vm | Get-NetworkAdapter | where {$_.macaddress -eq "$mac"} | select parent,macaddress

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × one =

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 comments

  1. Erik Thomson says:

    Can you help?

    I am looking for script that a can pull data from a txt file with 300+ MACs and it will out put the VMs that own the MACs.

    Thx in advance.

    • AlfPi says:

      Hi Eric,
      something like that would probably do the trick:

      $MACs = get-content -path c:\macs.txt
      $VMs = get-vm | Get-NetworkAdapter
      ForEach ($MAC in $MACs)
      {
      $VMs | where {$_.macaddress -eq "$MAC"} | select parent,macaddress
      }

      for this to work you need all your MAC addresses saved in c:\macs.txt file – one mac address per line:
      00:00:00:00:00:00
      11:11:11:11:11:11