Get Values from a Hyper-V Host About a Virtual Machine KVP

Learn how to read data from a VM from the Hyper-V host.

John Savill

December 3, 2013

1 Min Read
Get Values from a Hyper-V Host About a Virtual Machine KVP

Q: From the Hyper-V host, how can I get key value pair (KVP) information from a virtual machine (VM)?

A: The KVP functionality of Hyper-V enables data exchange between the guest OS in the VM and the Hyper-V host through the reading and writing of specific registry values. Guests can get information about the host they're running on by viewing values in HKEY_LOCAL_MACHINESOFTWAREMicrosoftVirtual MachineGuestParameters. For example, to get the host name of the Hyper-V host from within a VM I can use:

$regPath = "HKLM:SOFTWAREMicrosoftVirtual MachineGuestParameters"
(Get-ItemProperty -Path $regPath).HostName

It's a little more complex to get values from the Hyper-V host about a specific VM. WMI must be used. In the example below, I fetch the fully qualified domain name of the savdaldc02 VM. (The full list of available values can be found at Microsoft's website.

$vmName = "savdaldc02"$vm = Get-WmiObject -Namespace rootvirtualizationv2 -Class Msvm_ComputerSystem `    -Filter "ElementName='$vmName'"$vm.GetRelated("Msvm_KvpExchangeComponent").GuestIntrinsicExchangeItems | % {    $GuestExchangeItemXml = ([XML]$_).SelectSingleNode(`        "/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='FullyQualifiedDomainName']")    if ($GuestExchangeItemXml -ne $null)    {        $GuestExchangeItemXml.SelectSingleNode( `            "/INSTANCE/PROPERTY[@NAME='Data']/VALUE/child::text()").Value    }}

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like