Working with system locale and user locale

Last week while working with the WDRAP tool (Risk and Health Assessment Program for Windows Desktop) from Microsoft, it complained about the system locale not being en-US (English United States).

So I started digging into this subject and found that there are many ways to get the user locale.
You can query the $host variable in your powrshell session:


Or you can also simply query the $PSculture

get-item variable:\PSCulture

Or you can use the following .Net object:


You could also query the registry:

(Get-ItemProperty 'HKCU:\Control Panel\International').Locale
(Get-ItemProperty 'HKCU:\Control Panel\International').LocaleName

user locale

But, the user locale isn’t what I was looking for. The only way I found to query the System locale is by using WMI:

(Get-WmiObject Win32_OperatingSystem).locale

The WMI query returns a system string that is actually the hexadecimal number of the system locale. I was close to the result and finally used the System.Globalization.CultureInfo .Net object preloaded in the session.

The tip of the week page about Formatting Numbers and Dates Using the CultureInfo Object has a link to the .net object system.globalization.cultureinfo.

Here is how to use it

# The object accepts also a decimal number or a decimal number written in hexadecimal:

Now, I’ve just got to convert the system.string to either a decimal number or a decimal number written in hexadecimal like this:

# Using decimal number written in hexadecimal
[System.Globalization.CultureInfo]([int]("0x" + (Get-WmiObject Win32_OperatingSystem).locale))
# Using a decimal number, i.e, a system.int32
[System.Globalization.CultureInfo]([Convert]::ToInt32((Get-WmiObject Win32_OperatingSystem).locale,16))

Here are additional pages that could be as well useful resources:

This great page speaks also about the system.globalization.cultureinfo and much more:

This one shows how to Convert decimal to binary to hexadecimal and vice versa

This page explains precisely what Locale Names are.

And finally this page shows the full list of hexadecimal values and their Locale ID displayname:


One thought on “Working with system locale and user locale

  1. Pingback: PowerShell Culture and Help | Tony's Tech Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.