Freigeben über


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

Comments

  • Anonymous
    May 23, 2015
    But how to get VM IP addresses with VMM 2012 SP1?

  • Anonymous
    May 26, 2015
    Ben, I have been using Windows since Windows 3.11 (now I am using Windows 7) but still have no idea what is PowerShell and why should I prefer it to BAT-files (they look simpler to me). So can you recommend me one or two book about PowerShell. And also I want to know is it a replacement of BAT-files or just an addition? I mean how long BAT-files will be supported?

    • Anonymous
      July 27, 2016
      you can find all information on MVA site by key name "powershell"
  • Anonymous
    June 21, 2015
    Is there a way to make this work with non-Windows VMs? Dan

    • Anonymous
      July 27, 2016
      If you installed intergration kit inside non Windows VM you can get ip address.
  • Anonymous
    August 17, 2016
    I am using powershell version 2.0 on windows server 2008R2. I am trying to use the command Get-VM but it gives me error. My final conclusion is that 2.0 version does not support this command. Am I right? If so, then what is the solution? I want to know the IP addresses used by my virtual machines.

    • Anonymous
      March 27, 2017
      I use myself this in combination with SCVMM 2016Import-Module virtualmachinemanagerGet-SCVMHost | get-vm | Select -ExpandProperty VirtualNetworkAdapters | Select Name,IPv4Addresses,IPv4Subnets You might need to add SVMM host name to be able to run it.
  • Anonymous
    September 01, 2016
    I'm looking for a way to get the VM subnet mask along with the IP address. Does anyone know if there is a way?Thanks a lot!

  • Anonymous
    February 14, 2017
    hi how can i get ip of all hyper v machine and there sub a/c ip meaning 1 hyper v machine and there sub a/c