March 16, 2015

Powershell has Culture....

Grumpy Admin – Does it not really get your goat and make you grumpy, when you login to newly commissioned server, and the keyboard and region and language settings are WRONG? I am English, from the Great Kingdom that is United (well till the SNP get their way!).

We have a UK keyboard layout and have a local language installed en-GB. Shift-2 is ” not @…. (I direct you to read my blog post on colour/color for this argument!). Sometime having odd keyboard layouts and the likes can be a problem and can be easily over looked. So is there a real quick way of finding out what settings we have without too much clicking?  Let’s have a quick look at this from Powershell as in this global community we might actually have servers in different countries that we might need to administer. The internet and the IT department transcends international boundaries you know! So let’s have look at culture settings.

Get-Culture

cul1

That returns some information right away, LCID, Name, DisplayName – Which helps us no end. But what else is it hiding? Let’s find out by doing a Get-Member on the Get-Culture cmdlet. This shows us that there are quite a few bits of information about the current culture which can all be referenced.

So we can do something like this if we want to get the DisplayName quickly – Which could be handy in a $profile perhaps?

(Get-Culture).EnglishName

What else in that wealth of cultural information could be useful – oh look there a DateTimeFormat lets run that and have a look….

Now I will share with you a great tip – This is how I personally use and came to know about this culture information. Take this for example, say I have a script that lists days of the week. Grumpy Admin is lazy and there is nothing worse than typing.. Monday, Tuesday, Wednesday…… in to a string! But using this culture information, I never ever have to type shit like that in again! I can just do this :-

$days=(Get-Culture).DateTimeFormat.DayNames

cul2

How neat is that! A real time saver, and a very useful snippet for your collection- works with MonthGenitiveNames as well.

Now what was the LCID field, if you worked with Windows for any decent amount of time you will have come across directories in application like 1033… Now what that directory is can be explained with the following cmd

[system.globalization.cultureinfo]::getcultures(“AllCultures”)

cul3

1033 is the language code for English (United States) and as Microsoft is an American company, most of their products have this local as default… hence why you will see 1033 with the program resources. Different translations and languages will have their corresponding number.

In Windows 8 and Server 2012 upwards – Microsoft ships some great Powershell cmdlets like

Set-Culture

You can see all on these systems if you do a Get-Command -module International – Right – Time for Lunch… If not fed… Grumpy Admin might go all out and chew the arm off an annoying user!

Hazzy