Display Virtual Machine IPs using PowerShell

If you are like me, you have several VMs running on your desktop at all times. Sometimes you want to connect via RDP, or connect to a test database, or any other reason. And if you are also like me, you did not setup any type of DNS for your local VMs. So your only real option is IP addresses.

Get your IP Address in a VM

Now, you can login to each VM and get the IP addresses.

In Linux, we use a command such as ip addr

$ ip addr

In Windows we can use ipconfig

ipconfig

This is fine if you have one or two VMs. But what if you have multiple running with multiple OSes?
A much simpler solution is getting all of your VM IP addresses via PowerShell!

Get the IP addresses via PowerShell

Open a PowerShell window as an Administrator and execute the following command:

Get-VM | Where-Object {$_.State -eq "Running"} | Get-VMNetworkAdapter | Select-Object VMName, IPAddresses

The PowerShell command above returns the name of any running VMs and the IPv4 and IPv6 addresses.

You can now work with the machines above without logging into each and every machine.