Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created April 11, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/65d7585ed46ac265caee50e2640b5960 to your computer and use it in GitHub Desktop.
Save gitfvb/65d7585ed46ac265caee50e2640b5960 to your computer and use it in GitHub Desktop.
use another locale e.g. for outputting a date string
# cool function to create a date output in another locale
# SOURCE: https://stackoverflow.com/questions/2379514/powershell-formatting-values-in-another-culture
function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),
[ScriptBlock]$script=(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"))
{
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
$OldUICulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
try {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
Invoke-Command $script
}
finally {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture
}
}
Using-Culture en-GB { Get-Date -format "ddd, dd MMM yyyy HH:mm:ss zz00" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment