page hit counter
Welcome to MSDN Blogs Sign in | Join | Help

Taylor Brown's Blog

Test Lead for Windows Core OS Division on the Hyper-V Team.

Syndication

News

Welcome to the professional blog of Taylor Brown.  I am a test lead on the core virtualization team (Hyper-V) at Microsoft.

This blog will contain information about virtualization, Microsoft, Hyper-V, operating systems, testing, and whatever else I end up talking about...

 

Standard Microsoft Disclaimer:
"This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use."

-Taylor Brown


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 = <Previous Key Name>
$Msvm_KvpExchangeDateItem.Data = "Foo"
$Msvm_KvpExchangeDateItem.Source = 0

$VMManagementService.ModifyKvpItems($Vm, $Msvm_KvpExchangeDateItem.PSBase.GetText(1))

 

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

clip_image001

Published Wednesday, July 09, 2008 5:00 PM by taylorb

Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# a-foton &raquo; Hyper-V WMI: KVP Exchange aka Data Exchange (Retrieving and Modifying Parent/Host KVP???s) @ Wednesday, July 09, 2008 8:31 PM

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/

a-foton &raquo; Hyper-V WMI: KVP Exchange aka Data Exchange (Retrieving and Modifying Parent/Host KVP???s)

# re: Hyper-V WMI: KVP Exchange aka Data Exchange (Retrieving and Modifying Parent/Host KVP’s) @ Friday, July 11, 2008 1:29 AM

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!

Geoff

gnordli

# re: Hyper-V WMI: KVP Exchange aka Data Exchange (Retrieving and Modifying Parent/Host KVP’s) @ Tuesday, July 29, 2008 12:24 AM

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

taylorb

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
Page view tracker