Use-Culture


posted by Tobias
08-19-2010

Downloads: 256
File size: 1.3kB
Views: 1,794

Embed
Use-Culture
  1. <# 
  2.     .SYNOPSIS 
  3.         Executes PowerShell Code using specified culture 
  4.     .DESCRIPTION 
  5.         Temporarily switches culture from your default culture to another culture. 
  6.     .PARAMETER  culture 
  7.         Culture id for the culture you want to use, i.e. en-US for English culture, or de-DE for German culture 
  8.     .PARAMETER  code 
  9.         PowerShell code you want to run using the specified culture 
  10.     .EXAMPLE 
  11.         Use-Culture en-US {Get-Date
  12.         outputs the current date in US format 
  13.     .EXAMPLE 
  14.         Use-Culture de-DE {Get-Date
  15.         outputs the current date in German format 
  16.     .EXAMPLE 
  17.         Use-Culture ar-IQ {Get-Date
  18.         outputs the current date in Iraq format 
  19.     .NOTES 
  20.         Use this command to get a list of all supported culture IDs: 
  21.          [system.Globalization.CultureInfo]::GetCultures('AllCultures'
  22.     .LINK 
  23.         http://www.powershell.com 
  24. #> 
  25.  
  26. function Use-Culture
  27.     param
  28.             [System.Globalization.CultureInfo
  29.             [Parameter(Mandatory=$true)] 
  30.             $culture
  31.             [ScriptBlock
  32.             [Parameter(Mandatory=$true)] 
  33.             $code 
  34.         
  35.      
  36.         trap
  37.         [System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture 
  38.     
  39.      
  40.         $currentCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture 
  41.     [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture 
  42.     Invoke-Command $code 
  43.     [System.Threading.Thread]::CurrentThread.CurrentCulture = $currentCulture 
Filed under: ,
executes PowerShell code using a non-default culture
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.