08-19-2010
Downloads: 256
File size: 1.3kB
Views: 1,794
Embed
 |
Use-Culture |
- <
- .SYNOPSIS
- Executes PowerShell Code using specified culture
- .DESCRIPTION
- Temporarily switches culture from your default culture to another culture.
- .PARAMETER culture
- Culture id for the culture you want to use, i.e. en-US for English culture, or de-DE for German culture
- .PARAMETER code
- PowerShell code you want to run using the specified culture
- .EXAMPLE
- Use-Culture en-US {Get-Date}
- outputs the current date in US format
- .EXAMPLE
- Use-Culture de-DE {Get-Date}
- outputs the current date in German format
- .EXAMPLE
- Use-Culture ar-IQ {Get-Date}
- outputs the current date in Iraq format
- .NOTES
- Use this command to get a list of all supported culture IDs:
- [system.Globalization.CultureInfo]::GetCultures('AllCultures')
- .LINK
- http://www.powershell.com
-
-
- function Use-Culture {
- param(
- [System.Globalization.CultureInfo]
- [Parameter(Mandatory=$true)]
- $culture,
- [ScriptBlock]
- [Parameter(Mandatory=$true)]
- $code
- )
-
- trap {
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture
- }
-
- $currentCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
- Invoke-Command $code
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture
- }
executes PowerShell code using a non-default culture