Retrieving the IP Address Of A VM In Hyper-V

This post is to update an old from one 2008 Hyper-V WMI Using PowerShell Scripts – Part 3 (KVP’s – Guest OS Version) – in reviewing that post the most coming inquiry was looking for the guests IP address, well we got that for you in PowerShell now…  With the introduction of Windows Server 2012 Hyper-V now includes 164 different PowerShell cmdlet’s.  On of those is Get-VMNetworkAdapter and one of the properties we included in that cmdlet is the IPAddress that network adapter has assigned to it.  We retrieve that information using the tried and true key value pair integration component.

PowerShell Example

PS C:\> (Get-VMNetworkAdapter -VMName VM1).IpAddresses

WMI Example Querying The Key Value Pair (KVP) Integration Component

$vm = Get-WmiObject -Namespace root\virtualization\v2 -Class `
    Msvm_ComputerSystem -Filter {ElementName=VM1}

$vm.GetRelated("Msvm_KvpExchangeComponent").GuestIntrinsicExchangeItems | % { `
        $GuestExchangeItemXml = ([XML]$_).SelectSingleNode(`
        if ($GuestExchangeItemXml -ne $null)

Other Key Value Pair’s Provided

KVP Name Sample Value
OSName Windows Server 2008 R2 Enterprise
OSVersion 6.1.7601
CSDVersion Service Pack 1
OSMajorVersion 6
OSMinorVersion  1
OSBuildNumber 7601
OSPlatformId 2
ServicePackMajor 1
ServicePackMinor 0
SuiteMask 274
ProductType 3
OSVendor 1
OSSignature 4
OSEditionId 10
ProcessorArchitecture 9
IntegrationServicesVersion 6.2.9200.16433
NetworkAddressIPv6 fe80::3114:f7d4:4561:9ea2;2001:1234:a:2:7891:f7d4:4561:9ea2
RDPAddressIPv6 fe80::3114:f7d4:4561:9ea2;2001:1234:a:2:7891:f7d4:4561:9ea2



Comments (2)

  1. Anonymous says:

    Your post helped me a lot .I was deadly stuck up on retrieving domainname of vm from hyper-v.


  2. Ranjith M says:

    use this one

    (Get-VMNetworkAdapter -VMName <Name of the VM>).IpAddresses[0]