In the VMWare vSphere Client interface you can search virtual machines by their names only. But in some cases it is necessary to find the specific VMWare virtual machine by its IP or MAC (NIC hardware) address.
It is easier to do it using the VMWare PowerCLI that allows you to search by different virtual machine parameters.
Run the PowerCLI console and connect to your vCenter server or ESXi host using the following command:
Connect-VIServer vcenter-hq.contoso.com -User administrator
To find a virtual machine by its MAC address, use these commands:
$vmMAC="00:52:32:DD:12:91”
Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress –eq $vmMAC } | Select-Object Parent,Name,MacAddress
As you can see, the command has returned the name of the virtual machine with its MAC address.
You can also search for a specific MAC address directly in the virtual machine configuration files (VMX) on the VMFS datastore. Connect to your ESXi host via SSH and run the command:
find /vmfs/volumes | grep .vmx$ | while read i; do grep -i "00:52:32:DD:12:91" "$i" && echo "$i"; done
If you have VMware Tools installed on your virtual machines, you can search by the IP address of the guest operating system. For example, you have to find a VM with the specific IP address. Use the following commands:
$vmIP="192.168.1.102”
Get-VM * |where-object{$_.Guest.IPAddress -eq $vmIP}|select Name, VMHost, PowerState,GuestId,@{N="IP Address";E={@($_.guest.IPAddress[0])}}|ft
If you know only a part of the IP address, use the following command:
$vmIP="192.168.”
Get-VM * |where-object{$_.Guest.IPAddress -match $vmIP}|select Name, VMHost, PowerState,@{N="IP Address";E={@($_.guest.IPAddress[0])}} ,@{N="OS";E={$_.Guest.OSFullName}},@{N="Hostname";E={$_.Guest.HostName}}|ft
The command will list the names and types of installed OS’s of all virtual machines which IP addresses match this pattern.