Handling international WMI clients / servers with Hyper-V

Handling international WMI clients / servers with Hyper-V

  • Comments 5


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

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
  • I'm trying to get my server to respond to that exact command and it is in German, but I am still getting nothing with the -locale MS_409. Any thoughts as to why that might be?

    Thanks

  • William -

    Does it work if you do not use -locale?

    Cheers,

    Ben

  • Hi Ben,

    on my german Windows 7 its always german:

    PS C:\Users\Administrator> gwmi Win32_TimeZone | select StandardName

    StandardName

    ------------

    Mitteleuropäische Zeit

    PS C:\Users\Administrator> gwmi Win32_TimeZone -locale MS_409 | select StandardName

    StandardName

    ------------

    Mitteleuropäische Zeit

    What can I do?

    Cheers

    Enno

  • Thanks for putting together this summary information on the issue.

    Regarding the last part with things to note, specifically the third bullet "If you specify a locale which the server does not support – you will get English." - to me it seems that it would be more accurate to say that English will be the returned locale if it is installed on the target WMI server, otherwise the default system locale will be returned (e.g. I am testing on a system installed from Windows Server 2008 German image and there de-DE is the locale of the returned result)

    Thanks.

  • Would it be possible to also comment on how this is handled when using WSMAN / WinRM transport?

    I am testing the following scenario: from a Windows Server 2008 with German locale, using WinRM client, Msvm_ComputerSystem instances are enumerated from a remote Windows Server 2012 R2 with English as default locale and German locale installed in addition.

    It is then observed that the returned result is with English locale, although I can see that the wsman:Locale element is present in the WSMAN request with its xml:lang property set to de-DE.

    Same scenario but using PowerShell (WMI/DCOM? transport) yields a result with German locale.

Page 1 of 1 (5 items)