[kvptest.ps1]
┌──────────────────────────────────────┐
# Windows PowerShell script to test Key Value Pair functionality
#
# 以下のオリジナルのスクリプトは、Windows Server 2012 Hyper-V 以前、Hyper-V Server 2012 以前、および Windows 8 Hyper-V 以前で動作します。
#
http://http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/11/18/hyper-v-script-looking-at-kvp-guestintrinsicexchangeitems.aspx
#
# このスクリプトは、Windows Server 2012 R2 Hyper-V、Hyper-V Server 2012 R2、および Windows 8.1 Hyper-V 対応版です。
#
# 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\v2 -query $query -computername $HyperVServer
# Get the KVP Object
$query = "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
$Kvp = gwmi -namespace root\virtualization\v2 -query $query -computername $HyperVServer
Write-Host
Write-Host "Guest KVP information for" $VMName
# Filter the results
$Kvp.GuestIntrinsicExchangeItems | Import-CimXml
└──────────────────────────────────────┘
[kvptest.vbs]
┌──────────────────────────────────────┐
' Windows Script Host script to test Key Value Pair functionality
'
' 以下のオリジナルのスクリプトは、Windows Server 2012 Hyper-V 以前、Hyper-V Server 2012 以前、および Windows 8 Hyper-V 以前で動作します。
'
http://http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/11/18/hyper-v-script-looking-at-kvp-guestintrinsicexchangeitems.aspx
'
' このスクリプトは、Windows Server 2012 R2 Hyper-V、Hyper-V Server 2012 R2、および Windows 8.1 Hyper-V 対応版です。
'
Option Explicit
Dim HyperVServer
Dim VMName
Dim WMIService
Dim VM
Dim KVP
Dim xmlDoc
Dim DisplayString
Dim exchangeDataItem
Dim xpath
Dim node
'Prompt for the Hyper-V Server to use
HyperVServer = InputBox("Specify the Hyper-V Server to use (enter '.' for the local computer):")
'Get name for the virtual machine
VMName = InputBox("Specify the name of the virtual machine:")
'Get an instance of the WMI Service in the virtualization namespace.
Set WMIService = GetObject("winmgmts:\\" & HyperVServer & "\root\virtualization\v2")
'Get the VM object that we want
Set VM = (WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE ElementName='" & VMName & "'")).ItemIndex(0)
'Get the KVP Object for the virtual machine
Set KVP = (VM.Associators_("Msvm_SystemDevice", "Msvm_KvpExchangeComponent")).ItemIndex(0)
'Create an XML object to parse the data
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
'Iterate over GuestIntrinsicExchangeItems
for each exchangeDataItem in KVP.GuestIntrinsicExchangeItems
'Load single exchange data item
xmlDoc.loadXML(exchangeDataItem)
'Get the value for node name
xpath = "/INSTANCE/PROPERTY[@NAME='Name']/VALUE/child:text()"
set node = xmlDoc.selectSingleNode(xpath)
DisplayString = DisplayString & node.Text & " : "
'Get the data associated with the VM
xpath = "/INSTANCE/PROPERTY[@NAME='Data']/VALUE/child:text()"
set node = xmlDoc.selectSingleNode(xpath)
if not node is nothing then
DisplayString = DisplayString & node.Text & vbCrLf
else
DisplayString = DisplayString & vbCrLf
end if
next
wscript.echo "Guest KVP information for " & VMName & vbCrLf & vbCrLf & DisplayString
└──────────────────────────────────────┘
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。