Handling international WMI clients / servers with Hyper-V

If you ever try to run a WMI script / program against Hyper-V on a system that is using a language (or locale) different to your own – you may be surprised to see that a number of the properties are localized.  This can cause problems if you are checking for language specific strings.

Take the following example:

When retrieving a list of virtual machines from Hyper-V it is usual to look at the caption – in order to filter out the MSVM_ComputerSystem entry of the parent partition.  You would do this in PowerShell with a command like this:

 gwmi MSVM_ComputerSystem -namespace root\virtualization | where {$_.caption -eq "Virtual Machine"}

But if I run this command on a German installation of Windows:

Capture1

I get no results.  If I remove the where clause you can quickly see the problem:

Capture3

On this system the caption field is not “Virtual Machine” but is “Virtualler Computer”.

So what should you do to handle this?  Well – the answer is quite simple.  In WMI the server will always try to respond in the language that is used by the client.  Normally the client just picks up the language automatically – but you can manually specify a language to be used.  Here is the same PowerSehll command from above – but this time I am requesting that the server always respond in English:

 gwmi MSVM_ComputerSystem -namespace root\virtualization -locale MS_409 | where {$_.caption -eq "Virtual Machine"}

Running this yields the expected results:

Capture4

A couple of things to note here:

Cheers,

Ben