Using Cultures

by Dec 23, 2008

Since PowerShell is culture-independent, you can pick any culture you want and use the culture-specific formats. The following script instantiates the Japanese culture, outputting a number as currency first in your current culture and then in the Japanese culture.

$culture = New-Object System.Globalization.CultureInfo("ja-JP")
$number = 100
$number.toString('c')
$number.toString('c', $culture)

Learn more about what cultures are available and their identifiers by visiting MSDN: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

This works for many data formats such as toString(), which expects the data format you want to convert the data to: http://msdn.microsoft.com/en-us/library/fbxft59x(VS.80).aspx

Here is an example with dates:

(Get-Date).toString()
(Get-Date).toString("d", $culture)