How to get data (like the integration services version) from Msvm_KvpExchangeDataItem in Hyper-V

Today, if you are using VMM, you can quickly and easily find out if your VM has the integration components installed by using this simple PowerShell script.

<<

PS D:\Windows\system32> get-vm | select name, hostname, hasvmadditions, vmaddition | format-list

Name : vmonmlmich
HostName : car-1.contoso.com
HasVMAdditions : False
VMAddition : Not Detected

Name : win2k8r2
HostName : AMUNRA.contoso.com
HasVMAdditions : True
VMAddition : Detected
>>

The problem is that VMM does not give you the version information for the Integration Components in Hyper-V. if you would like to get that data, you need to use the Msvm_KvpExchangeDataItem property. Below is a script and its output that gives you all that data for all Running VMs with Integration Components installed in Hyper-V.

<<

Option Explicit

Dim WMIService
Dim KvpComponents
Dim VMList
Dim VM
Dim item
Dim component
Dim xml
Dim nodeValue
Dim nodeName

'Create the XML component
Set xml = createObject("MSXML2.DOMDOCUMENT.3.0")

'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization")

'Get all the MSVM_ComputerSystem object
Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem")   
For Each VM In VMList  
 if VM.Caption = "Virtual Machine" then      
 WScript.Echo "========================================"      
 WScript.Echo "VM Name: " & VM.ElementName      
 WScript.Echo "VM GUID: " & VM.Name
 WScript.Echo "VM State: " & VM.EnabledState   
 
 if VM.EnabledState <> 2 then
  Wscript.Echo "VM is not in a running state, so no KVPs can be exchanged"  
 end if

 ' Get the list of KvpComponents
 Set KvpComponents = WMIService.ExecQuery("SELECT * FROM Msvm_KvpExchangeComponent") '.ItemIndex(0)

 For Each component in KvpComponents

  ' ensure that we are displaying the correct settings for the VM based on its instance ID/Name
  If UCase(component.SystemName) = UCase(VM.Name) then

   Dim GuestItems
    GuestItems = component.GuestIntrinsicExchangeItems
 
   ' Now enumerate the Msvm_KvpExchangeDataItem's that are in XML format
   For Each item In GuestItems

  xml.async = false
  xml.resolveExternals = false
  xml.validateOnParse = false
  xml.loadXML item

   If xml.parseError.errorCode Then
         Wscript.Echo "--> Xml Document Parse Error: " & vbcrlf & _
                     " Reason = "  & xml.parseError.reason & vbcrlf & _
                     " Line = "    & xml.parseError.line & vbcrlf & _
                     " linePos = " & xml.parseError.linePos & vbcrlf & _
                    " srcText = " & xml.parseError.srcText & vbcrlf & _
                    " ErrorCode = " & xml.parseError.ErrorCode & vbcrlf
         'WScript.quit
   Else
   xml.setProperty "SelectionLanguage", "XPath"
   set nodeName = xml.selectSingleNode("//INSTANCE/PROPERTY[@NAME='Name']")
   set nodeValue = xml.selectSingleNode("//INSTANCE/PROPERTY[@NAME='Data']")
   Wscript.Echo nodeName.Text & " --> " & nodeValue.Text
  End If

   Next
  End If
 Next

 end if
Next
>>

 

Here is some example output as well. The Integration components version is the IntegrationServicesVersion property:

<<

========================================
VM Name: win2k8r2
VM GUID: 1D157259-F91F-4C61-8A1E-72F2C5BC112D
VM State: 2
FullyQualifiedDomainName --> MLMICH-WIN2K8-1.contoso.com
OSName --> Windows Server 2008 R2 Enterprise
OSVersion --> 6.1.7056
CSDVersion -->
OSMajorVersion --> 6
OSMinorVersion --> 1
OSBuildNumber --> 7056
OSPlatformId --> 2
ServicePackMajor --> 0
ServicePackMinor --> 0
SuiteMask --> 274
ProductType --> 3
OSEditionId --> 10
ProcessorArchitecture --> 9
IntegrationServicesVersion --> 6.1.7056.0
NetworkAddressIPv4 --> 172.30.181.72
NetworkAddressIPv6 --> 2001:4898:2a:3:8531:2f57:144c:3ce8;fe80::8531:2f57:144c:3ce8%14;2001:4898:0:fff:0:5efe:172.30.181.72;fe80::5efe:172.30.181.72%15
RDPAddressIPv4 --> 172.30.181.72
RDPAddressIPv6 --> 2001:4898:2a:3:8531:2f57:144c:3ce8;fe80::8531:2f57:144c:3ce8%14;2001:4898:0:fff:0:5efe:172.30.181.72;fe80::5efe:172.30.181.72%15
========================================

>>