Key Value Pair Exchange WMI Component Property GuestIntrinsicExchangeItems & Assumptions

Now that Windows 2008 R2 SP1 is being deployed some scripts to check whether the Integration Components (IC) in Hyper-V VM guests are upgraded came back on the radar screen. Host are being upgraded and thus the clients need upgraded IC as well. Now to check this for hundreds or thousands of guest we need some automation. PowerShell comes in handy for this and some neat scripts can be found around the internet. The most concise PowerShell code to do this, that I know of, is the one Peter Noorderijk (great Dutch IT Pro)  uses in his  PowerShell function Get-IntegrationServicesVersion on his blog How to check the version of the Integration Components.  As he provided this script just when I needed one I used it. This worked fine until I ran into an issue with it on some clusters. On two test clusters and two production clusters, it did the job as expected. On one test cluster and one production cluster, we ran into the situation where the output seemed wrong. The screenshot below is an example of this.

The red arrows indicate wrong data for the VMname and ICVersion. What happened here?  Well, when we read out the  GuestIntrinsicExchangeItems property from the WMI object Msvm_KvpExchangeComponent we get back XML. That XML needs to be parsed to display it for human consumption. The function depends on fixed positions containing the correct data. I’ve marked the relevant portions with a red arrow above, they come from$vmkvp[0] en $vmkvp[14] in the script below.

function Get-Integ.rationServicesVersion ($HVhost = $(throw “HVHost required”))
    {
    $kvps = Get-WmiObject -Namespace rootvirtualization -ComputerName $HVHost -Query “Select GuestIntrinsicExchangeItems From Msvm_KvpExchangeComponent”
        foreach ($kvp in $kvps)
         {
         $vmkvp = $Kvp.GuestIntrinsicExchangeItems
         $vmkvp | select-object @{Label=”VMHost”;Expression={$hvhost}},
                                @{Label=”VMName”;Expression={([xml]$vmkvp[0]).instance.property[1].value}},        
                                @{Label=”ICVersion”;Expression={([xml]$vmkvp[14]).instance.property[1].value}} -first 1
         }    
    }
  
foreach ($hvhost in get-content servers.txt) {Get-IntegrationServicesVersion $hvhost}

And indeed, when we dump the XML for two of the affected servers out to text files you can see the order is indeed different so counting on the exact location in an array is what tripped us up here.

Should this ever happen? Am I making a scripting mistake somewhere? Running a check with a VBScript that parses the XML  using XDOM (just in case my PowerShell skills are the cause of this) confirms the order is different but that the key pairs match up and are correct

D:SysAdminPowerShellScripts>cscript.exe test.vbs

Microsoft (R) Windows Script Host Version 5.8

Copyright (C) Microsoft Corporation. All rights reserved.

Guest OS information for server01

CSDVersion : Service Pack 1

FullyQualifiedDomainName : server01.lab.test

IntegrationServicesVersion : 6.1.7601.17514

NetworkAddressIPv4 : 10.10.100.118

NetworkAddressIPv6 : fe80::a177:729:8840:250%9

OSBuildNumber : 7601

OSEditionId : 7

OSMajorVersion : 6

OSMinorVersion : 1

OSName : Windows Server 2008 R2 Standard

OSPlatformId : 2

OSVersion : 6.1.7601

ProcessorArchitecture : 9

ProductType : 3

RDPAddressIPv4 : 10.10.100.118

RDPAddressIPv6 : fe80::a177:729:8840:250%9

ServicePackMajor : 1

ServicePackMinor : 0

SuiteMask : 272

D:SysAdminPowerShellScripts>cscript.exe test.vbs

Microsoft (R) Windows Script Host Version 5.8

Copyright (C) Microsoft Corporation. All rights reserved.

Guest OS information for server13

FullyQualifiedDomainName : server13.lab.test

OSName : Windows Server 2008 R2 Standard

OSVersion : 6.1.7601

CSDVersion : Service Pack 1

OSMajorVersion : 6

OSMinorVersion : 1

OSBuildNumber : 7601

OSPlatformId : 2

ServicePackMajor : 1

ServicePackMinor : 0

SuiteMask : 272

ProductType : 3

OSEditionId : 7

ProcessorArchitecture : 9

IntegrationServicesVersion : 6.1.7601.17514

NetworkAddressIPv4 : 10.10.100.112

NetworkAddressIPv6 : fe80::c18b:e3f2:7f05:31e4%12

RDPAddressIPv4 : 10.10.100.112

RDPAddressIPv6 : fe80::c18b:e3f2:7f05:31e4%12

When I look at where that data lives in the registry on those servers it all looks exactly the same, neatly ordered buy the RegEdit GUI:

So when getting that data from the Key-Value Pair Exchange WMI component with the property GuestIntrinsicExchangeItems you get a bunch of XML. That has to be parsed to be displayed in a readable fashion. The problem we are seeing is due to the fact that the items in the XML file are not in the same order. Peter’s function assumes it is. However this does not happen to be the case for most virtual machines, the majority is in the expected order. I don’t know why that is or if this is supposed to happen but it doesn’t seem to cause any harm. All is fully functional and operational in Hyper-V Manager, SCVMM 2008R2 … etc. Perhaps an MVP or Microsoft guru can shed some light on this. It seems like a bug waiting to happen if a developer of Hyper-V management software makes the same assumption. Of is this never suppose to happen and do I need to worry? I don’t know Smile I reinstalled the IC on the guests that have a different ordering and live migrated them, but that didn’t change anything

Anyway if you want to make sure you get the correct output we’ll need another approach that doesn’t make assumptions. You can roll your own and get the output customized to your needs but you need to parse the XML using a filter.  An example of this is listed below.

# 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      
 }    


# you send the output from the property to the filter via a pipe
$KvpComponentVMGuest.GuestIntrinsicExchangeItems $vmkvp |Import-CimXml 

Maarten Wijsman (a fellow blogger at http://www.hyper-v.nu like Peter)  has a nice example script here that also uses a filter Import-CimXML. Do note that there are variants on this filter depending on what output you desire that explains the difference between the filters.

New Functionality in Virtual Machine Manager Self Service Portal 2.0 SP1 Béta

It’s playtime! Via the Microsoft Connect site (you can get an invite to join the Connect site from TechNet page What’s New in System Center Virtual Machine Manager Self Service Portal 2.0 SP1 Beta, it below under “Join the Beta”) you can get your hands on the Virtual Machine Manager Self Service Portal 2.0 SP1 Béta. Some new features to highlight are the ability to import virtual machines (VMs that were removed from the self-service portal or VMs that are managed by SCVMM but are not created & available in the self-service portal). There are notifications available now for events using SQL mail so you can keep an eye on what is happening. Virtual Machine Templates can now be added to infrastructures (fast, no need for the entire request/provision process). You also get the option to move infrastructure between business units while in maintenance mode and even delete business units when they don’t own infrastructure. But the one I like best is the fact that we can expire virtual machines.

No, the last one doesn’t mean I want to be the bastard operator from hell that hates everyone and is so out of touch with the reality of “enabled” or “empowered” users or customers that he wants to seek & destroy them all. But when you’ve been in infrastructure for a while you’ve probably come across situations where the orphaned, abandoned, forgotten, virtual & yes even physical servers are working very hard on becoming a majority instead of an exception. This puts an enormous burden on the infrastructure, workload and it drives up costs very fast while it’s isn’t providing any ROI or other benefits to the business. Unless you’re getting paid to maintain infrastructure by the VM  (congrats!) and you just smile when you find 50% superfluous guests as this means the sound of your cash register ringing in your ears.

The thing is “Horror Vacui” comes into play and the inevitable desire of the universe for maximum entropy. So any environment will need some managing and it will be a welcome tool to help automate that management & enforce some decisions. You can even delegate this all via roles, so people can be empowered to set or change expiration dates. That way you can try to go for self-regulation. This can work.

Hyper-V Dynamic Memory does not work on a Windows Server 2008 Standard Edition or Windows Web Server 2008 virtual machine (VM)

Here’s a pointer to a Microsoft Knowledge base article on Hyper-v Dynamic Memory not working on Windows 2008 Standard & Web edition Hotfix: Hyper-V Dynamic Memory does not work on a Windows Server 2008 Standard Edition or Windows Web Server 2008 virtual machine (VM) As you probably already know you have a similar issue with Window 2008 R2 Standard and Web edition virtual machines which is fixed by installing SP1 in the guest. For the predecessor of R2 you need to install this hotfix.

The cause is that on these versions of the operating systems the the required memory enlightenment is supported. After installing the hotfix (or SP1 in the case of Windows 2008 R2) memory addition enlightenment is available on these SKU and your good to go.

Hyper-V Component Architecture Poster Updated With Windows 2008 R2 SP1 Features

You probably are all familiar with the component posters that Microsoft put out for Several technologies. You have the Exchange 2010 (Exchange Server 2010 Architecture Poster), Windows 2008 R2 (Windows Server 2008 R2 Feature Components Poster) & Hyper-V (Hyper-V Component Architecture).

I have them hanging on the walls around our offices and these make a great tool to discuss the technology and where what is being done or accomplished. Or as a reference when you need to explain some features.  I suggest you download them and have them plotted in a print shop.

Microsoft recently put out a new version of the Hyper-V Component Architecture poster with the Windows 2008 R2 Service Pack 1 features (Windows Server 2008 R2 Hyper-V Component Architecture (with Service Pack 1)). It’s nice to see that they update these so quickly.  We’re plotting this on A0 as we speak.