Thursday 24 December 2009

PowerShell V2 Download

This blog is mainly about PowerShell scripts. But from now on all scripts will be V2.0 and beyond. I have tested most of the scripts in the script library against V2 and will announce when that work is completed. In the meantime – if you are not running PowerShell V2 because you are on older OSs, help it is at hand.

Of course, if you are running Windows 7 or Windows Server 2008 R2, then you have PowerShell installed by default. On Windows 7, both the PowerShell console and PowerShell ISE are installed by default. On Server 2008 R2, PowerShell console is installed by default, whilst the PowerShell ISE is a feature you can add using Server Manager. And of course, for any Server 2008 R2 core installations, you would need to add both the .NET Framework and PowerShell – virtually nothing extra gets added to Server Core!

For down level (aka older) versions of Windows, Microsoft has released a KB article which directs you to versions you can download. Go to the page http://support.microsoft.com/kb/968929 where you can find PowerShell V2 for Windows XP, Vista, Server 2003 and Server 2008 (RTM) – in both 32-bit and 64-bit versions. Note that in Server 2008 RTM, PowerShell is not supported in Server Core.

In addition to PowerShell V2, the downloads also include the RTM version of Windows Remote Management (WinRM). WinRM is Microsoft’s  implementation of the standards based WS-Management Protocol. WinRM is based on Simple Object Access Protocol (SOAP), and provides a firewall-friendly protocol enabling hardware and operating systems from different vendors to interoperate.

If you are are using an older OS, i.e. Windows 2000 or earlier, then there is no supported version of PowerShell for you. You can probably hack some or even most of PowerShell V2 into those older OSs. But things may not work – and it’s not ever going to be supported.


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.    }