Hyper-V WMI: KVP Exchange aka Data Exchange (Retrieving and Modifying Parent/Host KVP’s)
On Sunday I showed how to add registry keys to the guest from the host (Hyper-V WMI: KVP Exchange aka Data Exchange (Adding New Items From Parent/Host)) and on Monday I showed how to read registry key’s written by the guest from the host (Hyper-V WMI- KVP Exchange aka Data Exchange (Adding New Items From Guest)). Today I am going to show how to retrieve previously added host keys and modify there values…
Retrieving Previously Added Key’s
filter Import-CimXml { $CimXml = [Xml]$_ $CimObj = New-Object -TypeName System.Object foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY")) { $CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE } $CimObj } $Vm = Get-WmiObject -Namespace root\virtualization -Query "Select * From Msvm_ComputerSystem Where ElementName='vista'" $Kvp = Get-WmiObject -Namespace root\virtualization -Query "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent" $GuestKvp = Get-WmiObject -Namespace root\virtualization -Query "Associators of {$Kvp} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_KvpExchangeComponentSettingData" $GuestKvp.HostExchangeItems | Import-CimXml |
Modifying Previously Added Key’s
This is almost identical to the script to add a KVP except in this case you need to provide a Name of an existing KVP and call the ModifyKvpItems method…
Note: If you are using my ProcessWMIObject function and getting a blank error message you should update to the latest version posted 7/6.
$ComputerName = "localhost" $VMManagementService = Get-WmiObject -class "Msvm_VirtualSystemManagementService" -namespace "root\virtualization" -ComputerName $ComputerName $Vm = Get-WmiObject -Namespace root\virtualization -ComputerName $ComputerName -Query "Select * From Msvm_ComputerSystem Where ElementName='Vista'" $Kvp = Get-WmiObject -Namespace root\virtualization -ComputerName $ComputerName -Query "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent" $Msvm_KvpExchangeDataItemPath = "\\$ComputerName\root\virtualization:Msvm_KvpExchangeDataItem" $Msvm_KvpExchangeDateItem = ([WmiClass]$Msvm_KvpExchangeDataItemPath).CreateInstance() $Msvm_KvpExchangeDateItem.Name = <PreviousKeyName> $Msvm_KvpExchangeDateItem.Data = "Foo" $Msvm_KvpExchangeDateItem.Source = 0 $VMManagementService.ModifyKvpItems($Vm, $Msvm_KvpExchangeDateItem.PSBase.GetText(1)) |
Taylor Brown
Hyper-V Integration Test Lead
https://blogs.msdn.com/taylorb
Comments
Anonymous
July 09, 2008
PingBack from http://blog.a-foton.ru/2008/07/hyper-v-wmi-kvp-exchange-aka-data-exchange-retrieving-and-modifying-parenthost-kvp%e2%80%99s/Anonymous
July 10, 2008
Is there any "caching" of keys. I can't seem to update an existing key. I can create a new key pair (works most of the time), but if I try to update it, then it doesn't seem take. thanks for scripts! GeoffAnonymous
July 28, 2008
Geoff, There is some caching of key's... If you add one you need to use update to update it or delete to delete it... Also when you update a key you have to push all of the key's. -Taylor