Using PowerShell to get VM IP addresses

Here is a handy PowerShell snippet:

Get-VM | ?{$_.ReplicationMode -ne "Replica"} | Select -ExpandProperty NetworkAdapters | Select VMName, IPAddresses, Status

Which delivers an output like this:

As you can see, it lists the IP addresses of all the virtual machines running under Hyper-V.  A couple of notes to make about this:

  • I use Hyper-V Replica heavily.  So I have developed the habit of always filtering out Replicas - so I do not worry about them.
  • I look at the network adapter status, because (as you can see) it allows me to tell the difference between a VM without an IP address - and a VM that is not reporting whether it has an IP address or not.

Hopefully you will find this useful in your environments.

Cheers,
Ben