Showing posts with label System.Globalization.CultureInfo. Show all posts
Showing posts with label System.Globalization.CultureInfo. Show all posts

Thursday, 16 May 2013

Show-CurrencyDecimalDigits.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the CurrencyDecimalDigits 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Show-CurrencyDecimalDigits.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 3.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted to: 
  14.          http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimaldigits%28v=vs.100%29.aspx 
  15. .EXAMPLE 
  16.     PSH> .\Show-CurrencyDecimalDigits.ps1 
  17.     ($1,234.00) 
  18.     ($1,234.0000) 
  19. #> 
  20.  
  21. # Get Number Format 
  22. $nf  = New-Object System.Globalization.CultureInfo  "en-US", $False  
  23. $nfi = $nf.NumberFormat 
  24.  
  25. # Display a negative value with the default number of decimal digits (2). 
  26. [Int64] $myInt = -1234 
  27. $myInt.ToString( "C", $nfi
  28.  
  29. # Displays the same value with four decimal digits. 
  30. $nfi.CurrencyDecimalDigits = 4 
  31. $myInt.ToString( "C", $nfi

Wednesday, 17 April 2013

Show-NumberDecimalSeparator.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the NumberDecimalSeparator
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Show-NumberDecimaleparatort.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 3.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted to: 
  14.          http://msdn.microsoft.com/en-us/library/b74zyt45%28v=vs.100%29.aspx 
  15. .EXAMPLE 
  16.     PSH> .\Show-NumberDecimalSeparator.ps1 
  17.     123,456,789.00 
  18.     123,456,789 00 
  19. #> 
  20.  
  21. # Get Number Format 
  22. $nf  = New-Object System.Globalization.CultureInfo  "en-US", $False  
  23. $nfi = $nf.NumberFormat 
  24.  
  25. [Int64] $myInt = 123456789 
  26. $myInt.ToString( "N", $nfi
  27.  
  28. $nfi.NumberDecimalSeparator = " " 
  29. $myInt.ToString( "N", $nfi

Wednesday, 13 March 2013

Show-CurrencyGroupSeparator.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the CurrencyGroupSeparator 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Show-CurrencyGroupSeparator.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 3.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted to: 
  14.          http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencygroupseparator%28v=vs.100%29.aspx 
  15. .EXAMPLE 
  16.     PSH> .\Show-NumberGroupSizes.ps1 
  17.     $123,456,789,012,345.00 
  18.     $123 456 789 012 345.00 
  19. #> 
  20.  
  21. # Get Number Format 
  22. $nf  = New-Object System.Globalization.CultureInfo  "en-US", $False  
  23. $nfi = $nf.NumberFormat 
  24.  
  25. # Display a value with the default separator (","). 
  26. [Int64] $myInt = 123456789012345 
  27. $myInt.ToString( "C", $nfi
  28.  
  29. # Displays the same value with a blank as the separator. 
  30. $nfi.CurrencyGroupSeparator = " " 
  31. $myInt.ToString( "C", $nfi

Tuesday, 7 August 2012

Show-Formatting1.ps1

  1. <#
  2. .SYNOPSIS
  3. MSDN Sample Recoded in PowerShell demonstrating formatting
  4. .DESCRIPTION
  5. This sample recodes an MSDN Sample into PowerShell that
  6. shows some of the options of formatting using ToString() and
  7. various .NET formatting strings
  8. .NOTES
  9. File Name : Show-Formatting1.ps1
  10. Author : Thomas Lee - tfl@psp.co.uk
  11. Requires : PowerShell Version 2.0
  12. .LINK
  13. This script posted to:
  14. http://www.pshscripts.blogspot.com
  15. MSDN sample posted to:
  16. http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
  17. .EXAMPLE
  18. Psh> .\Show-Formatting1.ps1\
  19. 00123
  20. 1.20
  21. 01.20
  22. 01,20
  23. 0.6
  24. 1,234,567,890
  25. 1.234.567.890
  26. 1,234,567,890.1
  27. 1,234.57
  28. #>
  29. ## Start script
  30. [double] $value = 123;
  31. $value.ToString("00000")
  32. # Displays 00123
  33. $value = 1.2;
  34. $value.ToString("0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  35. # Displays 1.20
  36. $value.ToString("00.00",[System.Globalization.CultureInfo]::InvariantCulture)
  37. # Displays 01.20
  38. $value.ToString("00.00",
  39. [System.Globalization.CultureInfo]::CreateSpecificCulture("da-DK"))
  40. # Displays 01,20
  41. $value = .56
  42. $value.ToString("0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  43. # Displays 0.6
  44. $value = 1234567890
  45. $value.ToString("0,0", [System.Globalization.CultureInfo]::InvariantCulture)
  46. # Displays 1,234,567,890
  47. $value.ToString("0,0",
  48. [System.Globalization.CultureInfo]::CreateSpecificCulture("el-GR"))
  49. # Displays 1.234.567.890
  50. $value = 1234567890.123456;
  51. $value.ToString("0,0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  52. # Displays 1,234,567,890.1
  53. $value = 1234.567890;
  54. $value.ToString("0,0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  55. # Displays 1,234.57

Sunday, 22 January 2012

New-SpanishCulture.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script creates a Spanish cultureinfo object with a traditional 
  4.      sort and another with an international sort. The script then compares them. 
  5. .DESCRIPTION 
  6.     This script re-implements an MSDN sample.  
  7. .NOTES 
  8.     File Name  : New-SpanishCulture.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN sample posted to: 
  15.          http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx    
  16. .EXAMPLE 
  17.     C:\foo> .\New-SpanishCulture.ps1 
  18.         PROPERTY                       INTERNATIONAL                                  TRADITIONAL               
  19.     CompareInfo                    CompareInfo - es-ES                            CompareInfo - es-ES_tradnl 
  20.     DisplayName                    Spanish (Spain)                                Spanish (Spain)           
  21.     EnglishName                    Spanish (Spain, International Sort)            Spanish (Spain, Traditional Sort) 
  22.     IsNeutralCulture               False                                          False                     
  23.     IsReadOnly                                                                    False                     
  24.     LCID                           3082                                           1034                      
  25.     Name                           es-ES                                          es-ES                     
  26.     NativeName                     Español (España, alfabetización internacional) Español (España, alfabetización tradicional) 
  27.     Parent                         es                                             es                        
  28.     TextInfo                       TextInfo - es-ES                               TextInfo - es-ES_tradnl   
  29.     ThreeLetterISOLanguageName     spa                                            spa                       
  30.     ThreeLetterWindowsLanguageName ESN                                            ESP                       
  31.     TwoLetterISOLanguageName       es                                             es                        
  32.  
  33.     Comparing [llegar] and [lugar] 
  34.        With myCIintl.CompareInfo.Compare: -1 
  35.        With myCItrad.CompareInfo.Compare: 1 
  36. #> 
  37.  
  38. # Create and initialize the CultureInfo which uses the international sort 
  39. $myCIintl = New-Object System.Globalization.CultureInfo "es-ES", $false 
  40.  
  41. # Create and initialize the CultureInfo which uses the traditional sort 
  42. $myCItrad = New-Object System.Globalization.CultureINfo 0x040A, $false 
  43.  
  44. # Display the properties of each culture. 
  45. "{0,-31}{1,-47}{2,-25}" -f "PROPERTY", "INTERNATIONAL", "TRADITIONAL" 
  46. "{0,-31}{1,-47}{2,-25}" -f "CompareInfo", $myCIintl.CompareInfo, $myCItrad.CompareInfo 
  47. "{0,-31}{1,-47}{2,-25}" -f "DisplayName", $myCIintl.DisplayName, $myCItrad.DisplayName 
  48. "{0,-31}{1,-47}{2,-25}" -f "EnglishName", $myCIintl.EnglishName, $myCItrad.EnglishName 
  49. "{0,-31}{1,-47}{2,-25}" -f "IsNeutralCulture", $myCIintl.IsNeutralCulture, $myCItrad.IsNeutralCulture 
  50. "{0,-31}{1,-47}{2,-25}" -f "IsReadOnly", $myCIintl.$IsReadOnly, $myCItrad.IsReadOnly 
  51. "{0,-31}{1,-47}{2,-25}" -f "LCID", $myCIintl.LCID, $myCItrad.LCID 
  52. "{0,-31}{1,-47}{2,-25}" -f "Name", $myCIintl.Name, $myCItrad.Name 
  53. "{0,-31}{1,-47}{2,-25}" -f "NativeName", $myCIintl.NativeName, $myCItrad.NativeName 
  54. "{0,-31}{1,-47}{2,-25}" -f "Parent", $myCIintl.Parent, $myCItrad.Parent 
  55. "{0,-31}{1,-47}{2,-25}" -f "TextInfo", $myCIintl.TextInfo, $myCItrad.TextInfo 
  56. "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterISOLanguageName", $myCIintl.ThreeLetterISOLanguageName, $myCItrad.ThreeLetterISOLanguageName 
  57. "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterWindowsLanguageName",$myCIintl.ThreeLetterWindowsLanguageName, $myCItrad.ThreeLetterWindowsLanguageName 
  58. "{0,-31}{1,-47}{2,-25}" -f "TwoLetterISOLanguageName", $myCIintl.TwoLetterISOLanguageName, $myCItrad.TwoLetterISOLanguageName 
  59. "" 
  60.  
  61. # Compare two strings using myCIintl 
  62. "Comparing [llegar] and [lugar]" 
  63. "   With myCIintl.CompareInfo.Compare: {0}" -f $myCIintl.CompareInfo.Compare("llegar", "lugar"
  64. "   With myCItrad.CompareInfo.Compare: {0}" -f $myCItrad.CompareInfo.Compare("llegar", "lugar"

Show-ChineeseParentCulture.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the parent culture of each  
  4.     specific culture using the Chinese language. 
  5. .DESCRIPTION 
  6.     This script looks at each Chineese culture and displays 
  7.     the culture name and the parent.  
  8. .NOTES 
  9.     File Name  : Show-ChineeseParentCulture.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15.     MSDN sample posted to: 
  16.          http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx    
  17. .EXAMPLE 
  18.     C:\foo> .\Show-ChineeseParentCulture.ps1 
  19.     SPECIFIC CULTURE                                     PARENT CULTURE 
  20.     0x0804 zh-CN Chinese (Simplified, PRC)               0x0004 zh-CHS Chinese (Simplified) Legacy 
  21.     0x0C04 zh-HK Chinese (Traditional, Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) Legacy 
  22.     0x1404 zh-MO Chinese (Traditional, Macao S.A.R.)     0x7C04 zh-CHT Chinese (Traditional) Legacy 
  23.     0x1004 zh-SG Chinese (Simplified, Singapore)         0x0004 zh-CHS Chinese (Simplified) Legacy 
  24.     0x0404 zh-TW Chinese (Traditional, Taiwan)           0x7C04 zh-CHT Chinese (Traditional) Legacy     
  25. #> 
  26.  
  27. # Display a header 
  28. "SPECIFIC CULTURE                                     PARENT CULTURE" 
  29.  
  30. # Determine the specific cultures that use the Chinese language, and displays the parent culture 
  31.  
  32. ForEach ($ci in [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::SpecificCultures))  { 
  33.   if ($ci.TwoLetterISOLanguageName -eq "zh"
  34.    { 
  35.     $s1 = "0x{0} {1} {2,-40}" -f $ci.LCID.ToString("X4"), $ci.Name, $ci.EnglishName 
  36.     $s2 = "0x{0} {1} {2}" -f $ci.Parent.LCID.ToString("X4"), $ci.Parent.Name, $ci.Parent.EnglishName 
  37.     "{0}{1}" -f $s1, $s2 
  38.   } 

Tuesday, 1 November 2011

Show-DateTimeFormatInfo.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements and MSDN sample that shows 
  4.     the different Date/Time Formatting characters and 
  5.     how they are used in formatting date/time objects. 
  6. .DESCRIPTION 
  7.     This script Creates a date/time object, then shows formatting 
  8.     using the key Date/Time Format strings. 
  9. .NOTES 
  10.     File Name  : Show-DateTimeFormatInfo.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx 
  18. .EXAMPLE 
  19.     Left as an exercise for the reader. 
  20.      
  21. #> 
  22.  
  23.  
  24. # Create and initialise a DateTimeFormatInfo associated with the en-US culture. 
  25.  $MyDTFI = (new-object System.Globalization.CultureInfo "en-US", $false ).DateTimeFormat 
  26.  
  27. # Create a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3) 
  28. # The Gregorian calendar is the default calendar for the en-US culture 
  29. $MyDT = new-object System.DateTime  2002, 1, 3  
  30.  
  31. # Display the format pattern associated with each format character 
  32. "FORMAT  en-US EXAMPLE" 
  33. "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY"  
  34. "  d     {0}"          -f $MyDT.ToString("d", $MyDTFI)  
  35. "        {0}    {1}`n" -f $MyDTFI.ShortDatePattern, "(ShortDatePattern)" 
  36. "  D     {0}"          -f $MyDT.ToString("D", $MyDTFI
  37. "        {0}    {1}`n" -f $MyDTFI.LongDatePattern, "(LongDatePattern)" 
  38. "  f     {0}`n"        -f $MyDT.ToString("f", $MyDTFI
  39. "  F     {0}"          -f $MyDT.ToString("F", $MyDTFI
  40. "        {0}    {1}`n" -f $MyDTFI.FullDateTimePattern, "(FullDateTimePattern)" 
  41. "  g     {0}`n"        -f $MyDT.ToString("g", $MyDTFI
  42. "  G     {0}`n"        -f $MyDT.ToString("G", $MyDTFI
  43. "  m     {0}"          -f $MyDT.ToString("m", $MyDTFI
  44. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  45. "  M     {0}"          -f $MyDT.ToString("M", $MyDTFI)  
  46. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  47. "  o     {0}`n"        -f $MyDT.ToString("o", $MyDTFI
  48. "  r     {0}"          -f $MyDT.ToString("r", $MyDTFI)  
  49. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  50. "  R     {0}"          -f $MyDT.ToString("R", $MyDTFI)  
  51. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  52. "  s     {0}"          -f $MyDT.ToString("s", $MyDTFI)  
  53. "        {0}    {1}`n" -f $MyDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" 
  54. "  t     {0}"          -f $MyDT.ToString("t", $MyDTFI)  
  55. "        {0}    {1}`n" -f $MyDTFI.ShortTimePattern, "(ShortTimePattern)" 
  56. "  T     {0}"          -f $MyDT.ToString("T", $MyDTFI)  
  57. "        {0}    {1}`n" -f $MyDTFI.LongTimePattern, "(LongTimePattern)" 
  58. "  u     {0}"          -f $MyDT.ToString("u", $MyDTFI)  
  59. "        {0}    {1}`n" -f $MyDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" 
  60. "  U     {0}`n"        -f $MyDT.ToString("U", $MyDTFI
  61. "  y     {0}"          -f $MyDT.ToString("y", $MyDTFI)  
  62. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 
  63. "  Y     {0}"          -f $MyDT.ToString("Y", $MyDTFI)  
  64. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 

Show-CurrencyDecimalSeparator.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN script which 
  4.     shows the use of the CurrencyDecimalSeparator 
  5.     property of a numeric format info object.  
  6. .DESCRIPTION 
  7.     This script displays a currency value using  
  8.     the default decimal separator then shows using a 
  9.     custom separator. This is repeated using a German 
  10.     culture.    
  11. .NOTES 
  12.     File Name  : Show-CurrencyDecimalSeparator.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimalseparator.aspx 
  20. .EXAMPLE 
  21.      Psh> .\Show-CurrencyDecimalSeparator.ps1 
  22.     $123,456,789.00 
  23.     $123,456,789 00 
  24.     123.456.789,00 € 
  25.     123.456.789 00 € 
  26. #> 
  27.  
  28. #    Get a NumberFormatInfo associated with the en-US culture 
  29. $nfi = (new-object System.Globalization.CultureInfo "en-US", $false ).NumberFormat 
  30.  
  31. #    Display a value with the default separator ("."). 
  32. $myInt = 123456789 
  33. $myInt.ToString( "C", $nfi )  
  34.  
  35. #    Display the same value with a blank as the separator. 
  36. $nfi.CurrencyDecimalSeparator = " " 
  37. $myInt.ToString( "C", $nfi )  
  38.  
  39. #    Now get a NumberFormatInfo associated with the de-DE culture 
  40. $nfi = (new-object System.Globalization.CultureInfo "de-DE", $false ).NumberFormat 
  41.  
  42. #    Display a value with the default separator (".") 
  43. $myInt = 123456789 
  44. $myInt.ToString( "C", $nfi )  
  45.  
  46. #    Display the same value with a blank as the separator 
  47. $nfi.CurrencyDecimalSeparator = " " 
  48. $myInt.ToString( "C", $nfi )  

Tuesday, 31 August 2010

Get-Cultures.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays information of cultures on a system. 
  4. .DESCRIPTION 
  5.     This script reimplements an MSDN script using PowerShell. It first 
  6.     gets the cultures then displays them 
  7. .NOTES 
  8.     File Name  : Get-Cultures.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://pshscripts.blogspot.com/2010/08/get-cultures.html 
  14.     MSDN sample posted to: 
  15.         http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultures.aspx  
  16. .EXAMPLE 
  17.     PSH [C:\foo]: .\Get-Cultures.ps1' 
  18.     CULTURE ISO ISO WIN DISPLAYNAME                             NATIVENAME 
  19.     af       af  afr AFK Afrikaans                               Afrikaans 
  20.     am       am  amh AMH Amharic                                 Amharic 
  21.     ar       ar  ara ARA Arabic                                  Arabic 
  22.     arn      arn arn MPD Mapudungun                              Mapudungun 
  23.     as       as  asm ASM Assamese                                Assamese 
  24.     az       az  aze AZE Azeri                                   Azeri 
  25.     az-Cyrl  az  aze AZC Azeri (Cyrillic)                        Azeri (Cyrillic) 
  26.     az-Latn  az  aze AZE Azeri (Latin)                           Azeri (Latin) 
  27.     ... snipped to save space! 
  28. #> 
  29.  
  30. # Get Cultures 
  31. $Cultures = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::NeutralCultures) 
  32.  
  33. # Display header then details 
  34. "CULTURE ISO ISO WIN DISPLAYNAME                             NATIVENAME" 
  35. foreach ($Ci in $Cultures
  36.       { 
  37. "{0,-8} {1,-3} {2,-3} {3,-3} {4,-40}{4,-40}" -f $Ci.Name, 
  38.              $Ci.TwoLetterISOLanguageName, 
  39.              $Ci.ThreeLetterISOLanguageName,   
  40.              $Ci.ThreeLetterWindowsLanguageName, 
  41.              $Ci.DisplayName, 
  42.              $Ci.NativeName 

Sunday, 28 February 2010

Using-Culture.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script creates a function to run culture sensitive operations
  4.     in some other culture. 
  5. .DESCRIPTION 
  6.     The Using-Culture function gets the current culture, saves it, then
  7.     runs the script block in the requested culture. The function then
  8.     restores the culture.  The script then ends with calls to
  9.     Using-Culture to demonstrate its use.
  10.  
  11.     The script is based on a blog note at: http://blogs.msdn.com/powershell/archive/2006/04/25/583235.aspx
  12. .NOTES 
  13.     File Name  : Using-Culture.ps1 
  14.     Author     : Thomas Lee - tfl@psp.co.uk 
  15.     Requires   : PowerShell Version 2.0 
  16. .LINK 
  17.     This script posted to: 
  18.         http://pshscripts.blogspot.com/2010/02/using-cultureps1.html
  19. .EXAMPLE 
  20.     run the script and see! 
  21. #> 
  22.  
  23. # Defind the Using-Culture function 
  24. Function Using-Culture { 
  25. Param ( 
  26. [System.Globalization.CultureInfo]$culture = (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"), 
  27. [ScriptBlock]$script= (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"
  28.     $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture 
  29.     trap  
  30.     { 
  31.         [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture 
  32.     } 
  33.     [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture 
  34.     Invoke-Command $script 
  35.     [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture 
  36. ## 
  37. # Now use the function 
  38. ## 
  39.  
  40. # Here is an example of Using-Culture 
  41. "Get-Date using ar-IQ" 
  42. using-culture ar-IQ {get-date} 
  43. "" 
  44. # Parse ar-IQ formatted date into local culture 
  45. "Parse IQ date to English and display" 
  46. $IQD = "30 تشرين الثاني, 2005 09:01:38 ص" 
  47. using-culture ar-IQ {$global:d=[DateTIme]::Parse($IQD)} 
  48. $IQD 
  49. $d 
  50. "" 
  51. # Now do it in German 
  52. "Get-Date using de-de" 
  53. using-culture de-de {get-date} 
  54. "" 
  55. "Parsing a german date into local" 
  56. $ded="Mittwoch, 30. November 2005 09:02:29" 
  57. using-culture de-de {$global:d=[DateTIme]::Parse($DED)} 
  58. $ded 
  59. $d 

Sunday, 13 December 2009

Get-LocaleCurrency.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays a number formatted in Currency for each locale 
  4. .DESCRIPTION 
  5.     This script first creates a value to be formatted, and creates an array 
  6.     containing all the locales defined on the system. The script then uses  
  7.     each locale to format the value as currency. 
  8. .NOTES 
  9.     File Name  : Get-LocaleCurrency.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     Left as an exercise for the reader! NB: the output will look better 
  17.     is this script is run in PowerShell ISE vs PowerShell console. 
  18.      
  19. #> 
  20. ## 
  21. # Start of script 
  22. ## 
  23.   
  24. #Create a value to be formatted 
  25. [int] $Value = 100 
  26.  
  27. # get all hte locales defined in the system 
  28. $L=[system.Globalization.CultureInfo]::GetCultures('AllCultures') | sort lcid 
  29.  
  30. foreach ($C in $L) { 
  31.  
  32. $C=New-Object System.Globalization.CultureInfo $C.Name 
  33. if (!$C.IsNeutralCulture){ 
  34.    "{0,-50} {1,-6}  {2}" -f $C.Displayname,$C.Name,$Value.ToString("C",$c
  35.    }