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 10.35.254.64 PoweredOn toolsOk
comp-vcenter01 10.35.254.63 PoweredOn toolsOk
mgt-nagios01 PoweredOff toolsNotRunning 9.4.0
mgt-lnxjump01 PoweredOn toolsNotInstalled
mgt-tempjump 169.254.241.21 PoweredOn toolsOld 9.4.0
mgt-dns01 10.35.254.4 PoweredOn toolsOld 9.4.0
mgt-vdiskhelper 10.35.254.26 PoweredOn toolsOld 9.4.0
mgt-loginsight03 10.35.254.83 PoweredOn toolsOk
mgt-nms PoweredOff toolsNotInstalled
mgt-dc02 10.35.254.9 PoweredOn toolsOld 9.4.0
mgt-dc01 10.35.254.7 PoweredOn toolsOld 9.4.0
mgt-loginsight02 10.35.254.82 PoweredOn toolsOk
mgt-dns02 10.35.254.5 PoweredOn toolsOld 9.4.0
mgt-bkp01 10.35.254.25 PoweredOn toolsOk
mgt-vrops01 10.35.254.36 PoweredOn toolsOk
mgt-loginsight01 10.35.254.81 PoweredOn toolsOk
mgt-pfsense PoweredOn toolsNotInstalled
mgt-ansible01 10.35.254.35 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 *

*