Freigeben über


Listing all the IP Addresses used by VMs

Here is a neat little snippet of PowerShell:

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

If you run this on a Hyper-V Server it will give you a listing of all the IP addresses that are assigned to running virtual machines:

image

This works whether you are using DHCP or Static IP addresses – and can really help when you are trying to track down a rogue virtual machine.

Cheers,
Ben

Comments

  • Anonymous
    April 23, 2014
    Great little tip, Ben. And modifying it by adding -ComputerName to the initial Get-VM command lets you run it against remote hosts.

  • Anonymous
    July 18, 2014
    Ben, is there a way to start and connect to VM from rootOS using Powershell?

  • Anonymous
    September 21, 2014
    i tried same command it is showing name but it is not showing ip address of virtual machines running. why is that.

  • Anonymous
    December 26, 2014
    This doesn't work if the VM is a generation1 VM

  • Anonymous
    September 24, 2015
    Sorry but this doesn't do anything.  No errors, no output, just does nothing.  The problem seems to be get-vm doesn't work unless you are in an elevated powershell.  However, at that point you only get the machine list, there are no IPs listed.  I'm guessing this is a bug or change was introduced since the guests show their IPs just fine in the Hyper-V Manager.  Too bad MAC and IP are not columns you can show in the VM list.

  • Anonymous
    September 24, 2015
    Ebonweaver - I would recommend that you review this article: blogs.msdn.com/.../why-do-you-have-to-elevate-powershell-to-use-hyper-v-cmdlets.aspx

  • Anonymous
    September 27, 2015
    Why are no IP addresses for W10 (Pro) VMs shown in the generated list from this script - all other O/S VMs DO show their IP address in the generated list? (Helpful script up until this ommision!) This is also the case in the Hyper-V Manager GUI as well - no IP addresses are listed for any W10 VMs in the Networking tab?? (Using W2012R2 Hyper-V Manager)

  • Anonymous
    October 03, 2015
    Karen - This works for me with W10 guests.  What host are you running?

  • Anonymous
    October 04, 2015
    We're using  2012R2 hypervisors - your script omits the IP addresses for the W10 VMS, and the Hyper-V Manager also omits displaying any IP addresses for the guest W10 VMs. The W10 guests are working just fine, full network and VPN access - but I have no way to see their IP address outside of the guest OS. Frustrating...and strange.