Thursday 25 December 2008

Get-Format1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates simple string formatting using Powershell 
  4. .DESCRIPTION 
  5.     This script formats 5 numbers in Decimal, Hex and Currency and is 
  6.     an adaptation of the C# sample in the MSDN Library 
  7. .NOTES 
  8.     Author   : Thomas Lee - tfl@psp.co.uk 
  9. .INPUTTYPE 
  10.    This script has no effective parameters. 
  11. .RETURNVALUE 
  12.    This script produces a short table of output, as shown in the Example. 
  13. .LINK 
  14.     http:////msdn.microsoft.com/en-us/library/fht0f5be.aspx 
  15.     http://www.pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.    PS C:\foo> .\Get-StringFormat1.ps1  
  18.    Decimal         Hex        Currency 
  19.     -32768:       8000   ($32,768.00) 
  20.        -27:   FFFFFFE5       ($27.00) 
  21.          0:          0          $0.00 
  22.       1042:        412      $1,042.00 
  23.      32767:       7FFF     $32,767.00 
  24. #> 
  25.  
  26. # Create an array of values to display 
  27. $values = [Int16]::MinValue, -27, 0, 1042, [Int16]::maxValue 
  28.  
  29. # Print header line then values 
  30.  "{0,10}  {1,10}  {2,14}" -f "Decimal", "Hex", "Currency" 
  31. foreach ($value in $values) { 
  32.     "{0,10:G}: {0,10:X} {0,14:C}" -f $value 

No comments: