list of ip addresses for hyper V machines RRS feed

  • General discussion

  • Hi Guys,

    i have an issue where everytime i restart my hyper V server there are list of hyper V machines that gets new IP, so if the IT staff needs that machine back i have manually go in the machine and find the ip address for all the machines - it a pain everytime.

    how i create a hyper V machine is based on parent child relation ship that is i have go hyper V VHD templates that i use as parent and use differencing disks to create new machines based on the different parents.

    i was looking into a way to get the IP list along with the virtual machine name using a power shell - i found the script on the blogs below:


    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

    ## – Use Line below to list all your Virtualization Class
    #get-wmiobject -namespace "root/virtualization" -list

    ## – Load filter (or function first)
    filter Import-CimXml{

        $CimXml = [Xml]$_
        $CimObj = New-Object -TypeName System.Object
        foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY")){
            if ($CimProperty.Name -eq "Name" -or $CimProperty.Name -eq "Data"){
                $CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE

    ## – Collect WMI Virtual information
    $getWmiVirtual = Get-WmiObject -Namespace "root\virtualization" -Query "Select * From Msvm_ComputerSystem" | sort-object elementname

    ## – Build your results from your collected objects
    ForEach($v in $getWmiVirtual){
        $vm = $v.ElementName;
        $VmObj = Get-WmiObject -Namespace "root\virtualization" -Query "Select * From Msvm_ComputerSystem Where ElementName='$vm'";
        $KvpObj = Get-WmiObject -Namespace "root\virtualization" -Query "Associators of {$VmObj} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent";
        if($KvpObj.GuestIntrinsicExchangeItems -ne $null){
            write-host $vm;
            $KvpObj.GuestIntrinsicExchangeItems | Import-CimXml | where {$_.NAME -match "NetworkAddressIPv4"} | ft;

    ## – End of Script

    this runs without an hitch but i get the results below:

     PS C:\users\ppatel\desktop> .\getip.ps1

    Data                                                        Name
    ----                                                        ----                                                NetworkAddressIPv4

    PaulWin7 - Do not shut down c Paul first, Use by ESS

    Data                                                        Name
    ----                                                        ----                                                NetworkAddressIPv4

    William/Johann Win2K8 X3

    Data                                                        Name
    ----                                                        ----                                                 NetworkAddressIPv4

    William/Johann X3DBServer

    which is not right i need the ip address for each virtual machine intact with it, i cant make the ip to static as per IT requirements.

    so i have to find an alternative using the script.

    please help.







    Wednesday, July 27, 2011 6:30 AM

All replies

  • Hi Parth,


    I ran the script on my system (Windows 2008 R2 SP1) and it returned each VM with its static or leased IP address just fine.

    In your output, I believe that you are getting several VM names without their equivalent IP Addresses, is that correct?



    Thanks, Wilson Souza - MSFT This posting is provided "AS IS" with no warranties, and confers no rights
    Thursday, July 28, 2011 5:53 AM
  • Yes that is true wilson.
    Tuesday, August 2, 2011 6:52 AM
  • Did you get this worked out?
    Thanks, Wilson Souza - MSFT This posting is provided "AS IS" with no warranties, and confers no rights
    Friday, January 13, 2012 8:49 AM