List all cultures by extending the native Get-Culture cmdlet

I recently needed to list all possible cultures available on a Windows box.
I’ve looked for a native cmdlet that you’d do it by typing:

Get-command *culture*


After using the Get-Member cmdlet on the output of the Get-Culture cmdlet, I found a .Net way of achieving this by doing:

[System.Globalization.CultureInfo]::GetCultures(
[System.Globalization.CultureTypes]::AllCultures
)

It’s nice and I thought that it would be great to have a -All switch on the native Get-Culture cmdlet.
Lee Holmes from the Windows PowerShell Team at Microsoft recently demonstrated a mind-blowing way of extending cmdlets with a few lines of code on his blog.

After playing with what Lee Holmes presented and how that would apply for extending the native Get-Culture cmdlet, I came up with this:

I’ve tested the above code on PowerShell version 2.0. Guess what! It works 😎

To get a sorted list of cultures that match the following pattern “en-US” for example, you can do (on PowerShell version 3.0):

Get-Culture -All | 
? Name -match "^[a-z]{2}-[A-Z]{2}$"  | 
Sort Parent

Advertisements

One thought on “List all cultures by extending the native Get-Culture cmdlet

  1. Pingback: Dew Drop – April 7, 2015 (#1988) | Morning Dew

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s