The Get-Culture
cmdlet shows you the current system “culture”. Culture is the stuff that defines the date formatting, number formatting, UI language, etc of your computer. Usually you set it in the Control Panel under Language/ Regional Settings, or when installing the OS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# Output on my system PS> get-culture LCID Name DisplayName ---- ---- ----------- 1033 en-US English (United States) # more verbose output PS> get-culture | Fl * Parent : en LCID : 1033 KeyboardLayoutId : 1033 Name : en-US IetfLanguageTag : en-US DisplayName : English (United States) NativeName : English (United States) EnglishName : English (United States) TwoLetterISOLanguageName : en ThreeLetterISOLanguageName : eng ThreeLetterWindowsLanguageName : ENU CompareInfo : CompareInfo - en-US TextInfo : TextInfo - en-US IsNeutralCulture : False CultureTypes : SpecificCultures, InstalledWin32Cultures, FrameworkCultures NumberFormat : System.Globalization.NumberFormatInfo DateTimeFormat : System.Globalization.DateTimeFormatInfo Calendar : System.Globalization.GregorianCalendar OptionalCalendars : {System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendar} UseUserOverride : True IsReadOnly : False |
The output is of the .NET type System.Globalization.CultureInfo
and has some useful static methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
PS> Get-Culture | gm TypeName: System.Globalization.CultureInfo Name MemberType Definition ---- ---------- ---------- ClearCachedData Method void ClearCachedData() Clone Method System.Object Clone(), System.Object ICloneable.Clone() Equals Method bool Equals(System.Object value) GetConsoleFallbackUICulture Method cultureinfo GetConsoleFallbackUICulture() GetFormat Method System.Object GetFormat(type formatType), System.Object IFormatProvider.Ge... GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Calendar Property System.Globalization.Calendar Calendar {get;} CompareInfo Property System.Globalization.CompareInfo CompareInfo {get;} CultureTypes Property System.Globalization.CultureTypes CultureTypes {get;} DateTimeFormat Property System.Globalization.DateTimeFormatInfo DateTimeFormat {get;set;} DisplayName Property string DisplayName {get;} EnglishName Property string EnglishName {get;} IetfLanguageTag Property string IetfLanguageTag {get;} IsNeutralCulture Property bool IsNeutralCulture {get;} IsReadOnly Property bool IsReadOnly {get;} KeyboardLayoutId Property int KeyboardLayoutId {get;} LCID Property int LCID {get;} Name Property string Name {get;} NativeName Property string NativeName {get;} NumberFormat Property System.Globalization.NumberFormatInfo NumberFormat {get;set;} OptionalCalendars Property System.Globalization.Calendar[] OptionalCalendars {get;} Parent Property cultureinfo Parent {get;} TextInfo Property System.Globalization.TextInfo TextInfo {get;} ThreeLetterISOLanguageName Property string ThreeLetterISOLanguageName {get;} ThreeLetterWindowsLanguageName Property string ThreeLetterWindowsLanguageName {get;} TwoLetterISOLanguageName Property string TwoLetterISOLanguageName {get;} UseUserOverride Property bool UseUserOverride {get;} PS> Get-Culture | gm -Static TypeName: System.Globalization.CultureInfo Name MemberType Definition ---- ---------- ---------- CreateSpecificCulture Method static cultureinfo CreateSpecificCulture(string name) Equals Method static bool Equals(System.Object objA, System.Object objB) GetCultureInfo Method static cultureinfo GetCultureInfo(int culture), static cultureinfo GetCul... GetCultureInfoByIetfLanguageTag Method static cultureinfo GetCultureInfoByIetfLanguageTag(string name) GetCultures Method static cultureinfo[] GetCultures(System.Globalization.CultureTypes types) ReadOnly Method static cultureinfo ReadOnly(cultureinfo ci) ReferenceEquals Method static bool ReferenceEquals(System.Object objA, System.Object objB) CurrentCulture Property static cultureinfo CurrentCulture {get;} CurrentUICulture Property static cultureinfo CurrentUICulture {get;} DefaultThreadCurrentCulture Property static cultureinfo DefaultThreadCurrentCulture {get;set;} DefaultThreadCurrentUICulture Property static cultureinfo DefaultThreadCurrentUICulture {get;set;} InstalledUICulture Property static cultureinfo InstalledUICulture {get;} InvariantCulture Property static cultureinfo InvariantCulture {get;} |
Using the Get-Culture
cmdlet I can check out the date-time format on any system:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Using the DateTimeFormat property PS> (Get-Culture).DateTimeFormat AMDesignator : AM Calendar : System.Globalization.GregorianCalendar DateSeparator : / FirstDayOfWeek : Sunday CalendarWeekRule : FirstDay FullDateTimePattern : dddd, MMMM d, yyyy h:mm:ss tt LongDatePattern : dddd, MMMM d, yyyy LongTimePattern : h:mm:ss tt MonthDayPattern : MMMM d PMDesignator : PM RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ShortDatePattern : M/d/yyyy ShortTimePattern : h:mm tt SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss TimeSeparator : : UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z' YearMonthPattern : MMMM yyyy AbbreviatedDayNames : {Sun, Mon, Tue, Wed...} ShortestDayNames : {Su, Mo, Tu, We...} DayNames : {Sunday, Monday, Tuesday, Wednesday...} AbbreviatedMonthNames : {Jan, Feb, Mar, Apr...} MonthNames : {January, February, March, April...} IsReadOnly : False NativeCalendarName : Gregorian Calendar AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr...} MonthGenitiveNames : {January, February, March, April...} |
Similarly I can check the number format, get the friendly name of the culture, etc.
I am more interested in the class itself: System.Globalization.CultureInfo
. Let’s examine its members again:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS> [System.Globalization.CultureInfo] | gm -static TypeName: System.Globalization.CultureInfo Name MemberType Definition ---- ---------- ---------- CreateSpecificCulture Method static cultureinfo CreateSpecificCulture(string name) Equals Method static bool Equals(System.Object objA, System.Object objB) GetCultureInfo Method static cultureinfo GetCultureInfo(int culture), static cultureinfo GetCul... GetCultureInfoByIetfLanguageTag Method static cultureinfo GetCultureInfoByIetfLanguageTag(string name) GetCultures Method static cultureinfo[] GetCultures(System.Globalization.CultureTypes types) ReadOnly Method static cultureinfo ReadOnly(cultureinfo ci) ReferenceEquals Method static bool ReferenceEquals(System.Object objA, System.Object objB) CurrentCulture Property static cultureinfo CurrentCulture {get;} CurrentUICulture Property static cultureinfo CurrentUICulture {get;} DefaultThreadCurrentCulture Property static cultureinfo DefaultThreadCurrentCulture {get;set;} DefaultThreadCurrentUICulture Property static cultureinfo DefaultThreadCurrentUICulture {get;set;} InstalledUICulture Property static cultureinfo InstalledUICulture {get;} InvariantCulture Property static cultureinfo InvariantCulture {get;} |
Particularly useful is the ability to examine another culture and then use the methods of that culture object to learn more about it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# What is the culture with LCID 1025? PS> [System.Globalization.CultureInfo]::GetCultureInfo(1025) LCID Name DisplayName ---- ---- ----------- 1025 ar-SA Arabic (Saudi Arabia) # Get its DateTimeFormat PS> ([System.Globalization.CultureInfo]::GetCultureInfo(1025)).DateTimeFormat AMDesignator : ص Calendar : System.Globalization.UmAlQuraCalendar DateSeparator : / FirstDayOfWeek : Saturday CalendarWeekRule : FirstDay FullDateTimePattern : dd/MMMM/yyyy hh:mm:ss tt LongDatePattern : dd/MMMM/yyyy LongTimePattern : hh:mm:ss tt MonthDayPattern : dd MMMM PMDesignator : م RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ShortDatePattern : dd/MM/yy ShortTimePattern : hh:mm tt SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss TimeSeparator : : UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z' YearMonthPattern : MMMM, yyyy AbbreviatedDayNames : {الأحد, الإثنين, الثلاثاء, الأربعاء...} ShortestDayNames : {ح, ن, ث, ر...} DayNames : {الأحد, الإثنين, الثلاثاء, الأربعاء...} AbbreviatedMonthNames : {محرم, صفر, ربيع الأول, ربيع الثاني...} MonthNames : {محرم, صفر, ربيع الأول, ربيع الثاني...} IsReadOnly : True NativeCalendarName : تقويم ام القرى AbbreviatedMonthGenitiveNames : {محرم, صفر, ربيع الأول, ربيع الثاني...} MonthGenitiveNames : {محرم, صفر, ربيع الأول, ربيع الثاني...} |
More later!