VMWare: How to Find VMs by IP or MAC Address

VMWare: How to Find VMs by IP or MAC Address

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. This can be easily done by PowerCLI, provided that the VMware Tools are installed in each VM.

Quick download PowerCLI from here , install and run it.

Or you can Copy and Paste the following command to install this package using PowerShell Install-Module

PS> Install-Module -Name VMware.PowerCLI

If you are having problems with PowerShell, please click here .

Step One – Connect To VCenter

Run PowerShell and Run the following command to connect to vCenter:

Connect-VIServer vcenter-IP-or-DOMAIN -User administrator@vsphere.local

Connect to VMware PowerCLI Connect to VMware PowerCLI

Step Two – Search VM by IP Address

Here is the command to find which IP Address belongs to a VM:

Get-VM * |where-object{$_.Guest.IPAddress -eq "10.222.22.25"}|select Name,  VMHost, PowerState,GuestId,@{N="IP  Address";E={@($_.guest.IPAddress[0])}}|ft

example:

Get-VM * |where-object{$_.Guest.IPAddress -eq "192.168.0.206"}|select Name,  VMHost, PowerState,GuestId,@{N="IP  Address";E={@($_.guest.IPAddress[0])}}|ft

Find VMware VM by IP Addres - eq Find VMware VM by IP Addres - eq

If you know only a part of the IP Address, you can search using the following command:

Get-VM * |where-object{$_.Guest.IPAddress -match "192.168.0."}|select  Name, VMHost, PowerState,@{N="IP Address";E={@($_.guest.IPAddress[0])}}  ,@{N="OS";E={$_.Guest.OSFullName}},@{N="Hostname";E={$_.Guest.HostName}}|ft

Find VMware VM by IP Address - match Find VMware VM by IP Address - match

You can see a list with all VMs if you run this command:

Get-VM * |%{$_.Guest}|%{$_.IPAddress}

Step Three – Search VM by MAC Address

If you know the MAC and want to find out to which VM belongs, you ca run the command:

Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress eq $vmMAC } | Select-Object Parent,Name,MacAddress

example:

PS C:\WINDOWS\system32> Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -eq "00:50:56:8f:4f:e7" } | Select-Object Parent,Name,MacAddress

Find VMware VM by MAC Address - eq Find VMware VM by MAC Address - eq

If you know only a part of the MAC Address, you can search using the following command:

Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress match $MAC_PART } | Select-Object Parent,Name,MacAddress

example:

PS C:\WINDOWS\system32> Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -match "4f:e7" } | Select-Object Parent,Name,MacAddress

Find VMware VM by part of MAC Address - match Find VMware VM by part of MAC Address - match

VMware VMFS

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

SUBSCRIBE FOR NEW ARTICLES

@
comments powered by Disqus