Query IP address (and other info) of Virtual Machine

I’ve been working on some different things lately and wanted to share with you a tool I used to help verify data. Whilst I am not ready to reveal all that I am working on I have had the requirement to return the following information about a Virtual Machine – Name, IP Address, MAC Address, Attached Network, Power State, VMtools status, and the VMtools version.

One thing I did not want to do is to hunt around do this manually or via GUI. The cluster I am working on has ~50 management machines whilst the compute cluster has anywhere between 100-800 machines. I need to know if an IP address is assigned to a virtual object or outside the scope of the virtual domain (ala, physical or remote source)

It is important to remember that VMtools is A method of validation but should not be the only one. VMtools may not be 100 percent reliable.

Get-VM | Select Name, @{N="IP Address";E={@($_.Guest.IPAddress[0])}}, @{N="PowerState";E={@($_.PowerState)}}, @{N="VMTools Status";E={@($_.ExtensionData.Guest.ToolsStatus)}}, @{N="VMTools Version";E={@($_.Guest.ToolsVersion)}}| ft -auto |s

Which results in something like the below:

Screenshot 2016-04-30 21.55.54

PowerCLI C:\> Get-VM | Select Name, @{N="IP Address";E={@($_.Guest.IPAddress[0])}}, @{N="PowerState";E={@($_.PowerState)}}, @{N="VMTools Status";E={@($_.ExtensionData.Guest.Tool
atus)}}, @{N="VMTools Version";E={@($_.Guest.ToolsVersion)}}| Ft -auto

Name IP Address PowerState VMTools Status VMTools Version
---- ---------- ---------- -------------- ---------------
mgt-vcenter01 PoweredOn toolsOk
comp-vcenter01 PoweredOn toolsOk
mgt-nagios01 PoweredOff toolsNotRunning 9.4.0
mgt-lnxjump01 PoweredOn toolsNotInstalled
mgt-tempjump PoweredOn toolsOld 9.4.0
mgt-dns01 PoweredOn toolsOld 9.4.0
mgt-vdiskhelper PoweredOn toolsOld 9.4.0
mgt-loginsight03 PoweredOn toolsOk
mgt-nms PoweredOff toolsNotInstalled
mgt-dc02 PoweredOn toolsOld 9.4.0
mgt-dc01 PoweredOn toolsOld 9.4.0
mgt-loginsight02 PoweredOn toolsOk
mgt-dns02 PoweredOn toolsOld 9.4.0
mgt-bkp01 PoweredOn toolsOk
mgt-vrops01 PoweredOn toolsOk
mgt-loginsight01 PoweredOn toolsOk
mgt-pfsense PoweredOn toolsNotInstalled
mgt-ansible01 PoweredOn toolsOld 9.4.0
#Output Snipped#

Perfect. A quick way to validate what I needed and now I need to find a way to read “Discovered IPs” by NSX DHCP and ARP discovery methods. That will give me a better source of truth. For now I can use this output for other things now! Stay tuned!

Leave a Reply

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