Share via


Hyper-V WMI: KVP Exchange aka Data Exchange (Adding New Items From Guest)

Update 12/5/12

A lot has changed since 2008 and many things have stayed the same…  I wanted to provide an update to some of the most commonly viewed posts and this was one of them.

For updated information on this topic please refer to my latest post Customizing The Key Value Pair (KVP) Integration Component.

 

Original Post

Yesterday’s post (Hyper-V WMI: KVP Exchange aka Data Exchange (Adding New Items From Parent/Host)) showed how to add registry key’s into the guest so that the guest could receive information from the host.  Today’s post will show how to add a registry key in the guest so that the host can retrieve it…

Step 1 – Add a registry key to the guest…

Use your faviorite registy editing tool such a reg.exe or powershell.

Examples:
Reg.exe: reg add "HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest" /v test /t REG_SZ /d testing
Powershell: New-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest" -name test2 -value testing

Step 2 – Query the value from the host…

This might look very similar to Hyper-V WMI Using PowerShell Scripts – Part 3 (KVP's - Guest OS Version) it is…(just the last line changes :-))

filterImport-CimXml {     $CimXml= [Xml]$_     $CimObj=New-Object-TypeNameSystem.Object     foreach ($CimPropertyin$CimXml.SelectNodes("/INSTANCE/PROPERTY")) {         $CimObj|Add-Member-MemberTypeNoteProperty-Name$CimProperty.NAME-Value$CimProperty.VALUE }     $CimObj } $Vm=Get-WmiObject-Namespaceroot\virtualization-Query"Select * From Msvm_ComputerSystem Where ElementName='vista'" $Kvp=Get-WmiObject-Namespaceroot\virtualization-Query"Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent" $Kvp.GuestExchangeItems|Import-CimXml

Output:

Caption : Data : testing Description : ElementName : Name : test Source : 1

Caption : Data : testing Description : ElementName : Name : test2 Source : 1

 

Taylor Brown
Hyper-V Integration Test Lead
https://blogs.msdn.com/taylorb

clip_image001

Comments