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.
PS C:\> (Get-VMNetworkAdapter -VMName VM1).IpAddresses 192.168.0.104 fe80::3114:f7d4:4561:9ea2 2001:1234:a:2:7891:f7d4:4561:9ea2
$vm = Get-WmiObject -Namespace root\virtualization\v2 -Class ` Msvm_ComputerSystem -Filter {ElementName='VM1'}
$vm.GetRelated("Msvm_KvpExchangeComponent").GuestIntrinsicExchangeItems | % { ` $GuestExchangeItemXml = ([XML]$_).SelectSingleNode(` "/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='NetworkAddressIPv4']") if ($GuestExchangeItemXml -ne $null) { $GuestExchangeItemXml.SelectSingleNode(` "/INSTANCE/PROPERTY[@NAME='Data']/VALUE/child::text()").Value } }
-taylorb