Understanding the get-culture command

你。 提交于 2021-01-28 12:04:40

问题


I recently had some trouble with culture dependent returned values from my powershell script. The same script returned different values, depending on which machine it was. So I thought that maybe the culture settings are different and for one server it returned.

get-culture : de-DE

for the other it was like : en-US

One value is for the keyboard settings but what does the other (second) stand for?

And is the second value bound to the OS installation or is that just a setting? Is there a command in powershell to change the value?

Of course I first read the gelp get-help get-culture

DESCRIPTION
    The Get-Culture cmdlet gets information about the current culture settings. This includes information about the
    current language settings on the system, such as the keyboard layout, and the display format of items such as
    numbers, currency, and dates.

But I am not satisfied with it.


回答1:


The help for the Cmdlet Get-Culture contains a subheading name related links. Please note the last 2 lines.

Related Links
Online Version: http://go.microsoft.com/fwlink/p/?linkid=293965
Set-Culture
Get-UICulture

When searching for help also use the Get-Command Cmdlet.

Get-Command "*culture*"

You can view your 'current culture' by using the built in Powershell variables.

$PSCulture
$PSUICulture

The following code block returns the short date pattern of three different cultures.

### Creates an array of cultureinfo objects:
$myCulturesArray = @(    
    ( $myDECulture = New-Object System.Globalization.CultureInfo("de-DE") ),
    ( $myGBCulture = New-Object System.Globalization.CultureInfo("en-GB") ),
    ( $myUSCulture = New-Object System.Globalization.CultureInfo("en-US") )
);

### Outputs today's date using each CultureInfo object
$myCulturesArray | foreach { 
  (Get-date).ToString('d', $_ ) 
}

Further reading:

Tobias Weltner put together a very useful set of pdfs, volume 3 is on culture.
Also, at the prompt:

Get-Help Get-Culture -Full
help about_Script_Internationalization


来源:https://stackoverflow.com/questions/22797798/understanding-the-get-culture-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!