In this post you’ll find two scripts that will help you find a VM via an IP or MAC address. I found the MAC address script on the vmtn communities and it was written by Luc Dekens (@LucD22):
http://communities.vmware.com/message/1068045#1068045
IP Address:
The following script will return the VM name after a short search. The only thing you need to enter is the ip address:
$tgtIP = "192.168.123.1" $vms = Get-VM foreach($vm in $vms){ $vmIP = $vm.Guest.IPAddress foreach($ip in $vmIP){ if($ip -eq $tgtIP) { Write-Host "Found the VM!" $vm.Name } } }
When you add the script to the Virtualizaion Eco Shell, you will have to change the $tgtIP line:
$tgtIP = Read-Host "enter IP address"
When you run the script from the Eco Shell, you’ll have to enter an ip address:
After a couple of seconds (if you have a large environment it will take a while 😉 ) The script will return the VM name:
MAC Address
The following script start a search based on the MAC address of the VM.
$tgtMAC = "" $vms = Get-VM foreach($vm in $vms){ $vmMAC = $vm | Get-NetworkAdapter | select MacAddress foreach($mac in $vmMAC){ if($mac.MacAddress -eq $tgtMAC) { Write-Host "Found the VM!" $vm.Name } } }
You can also add the script to the Eco Shell. Just change the $tgtMAC line to:
$tgtMAC = Read-Host "enter MAC address"
work! but the time to execute is low