Hyper-V Script: Looking at KVP GuestIntrinsicExchangeItems
You may wonder what that title is about, so let me pause to explain things a little. One of the Integration Components that gets installed inside the virtual machine with Hyper-V is the "KVP" component - which stands for "Key Value Pair". This is the component that enables the exchange of basic string data between the parent and child environments. The KVP data is then broken down into three categories:
- HostExchangeItems
- This is information being sent from the parent partition to the guest operating system.
- GuestExchangeItems
- This is information being sent from the guest operating system to the parent partition.
- GuestIntrinsicExchangeItems
- This is information that is automatically sent from the guest operating system to the parent partition.
Today I want to show you how to get the information from the last category and display it in the parent partition. The biggest challenge with doing this is handling the fact that this data is returned as an XML blob that you need to parse correctly to display the results.
{See Ben's Post for vbscript version}
PowerShell
# Filter for parsing XML data
filter Import-CimXml
{
# Create new XML object from input
$CimXml = [Xml]$_
$CimObj = New-Object -TypeName System.Object
# Iterate over the data and pull out just the value name and data for each entry
foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Name']"))
{
$CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE
}
foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Data']"))
{
$CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE
}
# Display output
$CimObj
}
# Prompt for the Hyper-V Server to use
$HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"
# Prompt for the virtual machine to use
$VMName = Read-Host "Specify the name of the virtual machine"
# Get the virtual machine object
$query = "Select * From Msvm_ComputerSystem Where ElementName='" + $VMName + "'"
$Vm = gwmi -namespace root\virtualization -query $query -computername $HyperVServer
# Get the KVP Object
$query = "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
$Kvp = gwmi -namespace root\virtualization -query $query -computername $HyperVServer
Write-Host
Write-Host "Guest KVP information for" $VMName
# Filter the results
$Kvp.GuestIntrinsicExchangeItems | Import-CimXml
This should provide you with output like this:
Cheers,
BenPublished Tuesday, November 18, 2008 1:29 AM by Virtual PC Guy
Virtual PC Guy's WebLog : Hyper-V Script: Looking at KVP GuestIntrinsicExchangeItems
No comments:
Post a Comment