TONYSO

Tonyso Credo: "Look for a pattern, and solve it for everything"

Hyper-V How To: Get Intrinsic KVPS using Script

Hyper-V How To: Get Intrinsic KVPS using Script

  • Comments 1
  • Likes

Some friends here on the Hyper-V team shared a PowerShell 2.0 script for getting an intrinsic KVPS:

# Get Intrinsic KVPs (Included Guest machine name, IC Version, OS Version, etc)

param(
    [string]$vmName = $(throw "Must specify virtual machine name")
)

$vm = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName='$vmName'"

# Get the associated KVP Exchange component
$kvp = gwmi -namespace root\virtualization `
    -query "Associators of {$vm} where ResultClass=Msvm_KvpExchangeComponent"

# Pull the Guest Intrinsic Exchange Items from XML into a hash
$kvpHash = @{}
if($kvp.GuestIntrinsicExchangeItems){
    ([xml]("<xml>"+$kvp.GuestInstrinsicExchangeItems+"</xml>")).xml.instance | `
        foreach{$kvphash.add($_.property[4].value,$_.property[1].value)}
}
return $kvpHash

For more info on how to use PS cmdlets see: http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/index.mspx

See also James O’Neil’s New and improved PowerShell Library for Hyper-V. Now with more functions and... documentation!

For all 35 sample Hyper-V PS1 scripts in a zipfile, go to: Hyper-V%20PowerShell%20Example%20Scripts.zip-download

Comments
  • I'm unable to download the Hyper-V sample scripts library. The link seems not to be valid.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment