A few days ago one of my colleagues called me and asked me to add 4 HDDs to a Windows VM. Then he e-mailed me the name of the VM. I said to him that it will be ready in a few minutes.
Then I’ve connected to vCenter and look after the name. No VM with this name in the cluster. I’ve contacted my colleague and asked him to send me the IP address cause it seems there is no VM with this name.
OK, now I have the IP, but it seems that is not possible to search in vCenter Web Client after the IP address. There are more than 100 VMs in this cluster, I don’t want to check manually each one.
I would need an automatically method cause I have to help my colleague quite fast. Google is saying that would be possible with VMWare PowerCLI.
Quick download PowerCLI from here, installed and ran it.
If you are having problems when starting PowerCLI, please check here.
Let’s see what you have to do if you want to find a VM after IP.
Step one – connect to vCenter
Run the following command to connect to vCenter:
Connect-VIServer vcenter-IP -User administrator@vsphere.local
Step two – search VM after IP Address or MAC
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
If you know only a part of the IP Address, you can search using the following command:
Get-VM * |where-object{$_.Guest.IPAddress -match "10.122.225."}|select Name, VMHost, PowerState,@{N="IP Address";E={@($_.guest.IPAddress[0])}} ,@{N="OS";E={$_.Guest.OSFullName}},@{N="Hostname";E={$_.Guest.HostName}}|ft
You can see a list with all VMs if you run this command:
Get-VM * |%{$_.Guest}|%{$_.IPAddress}
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
Pretty cool this PowerCLI, it could be helpful in many situations. Enjoy using it and see you at the next post.