Tuesday, June 19, 2012

Upgrading to Powershell 3.0 on Windows 2008 R2 SP1


Having been tasked with the upgrade of Windows PowerShell from version 2.0 to version 3.0 on a bunch of Windows 2008 R2 servers, I thought I could share my experience with this kind of activity and help you not to get muddled up. I will try to be as clear as possible and detail the steps to follow as well as identify the milestones of the upgrade.

First of all know that Windows PowerShell 3.0 is part of a greater package known as Windows Management Framework (WMF 3.0). WMF contains Windows PowerShell 3.0 (of course...), WMI and WinRM. The Beta version also includes a Server Manager CIM provider. This CIM provider allows users of Server Manager in Windows Server 2012 to collect and view management data from servers with Windows Management Framework 3.0 installed.

The Beta version of WMF 3.0 is shipped in four different packages. The package we are interested to is Windows6.1-KB2506143-x64.msu, which is targeted for Windows 2008 R2 SP1. You can download it from this link.

Before we start the upgrade, check that four prerequisites are met:
  • you have SP1 ( if not, download the pretty huge (903MB) file here)
  • you are running the x64 edition (Windows 2008 R2 exists only in 64 bit...)
  • you have installed the full version of .NET 4.0 (available here for Full Windows installation and here if you have the the Server Core version of Windows 2008 R2 SP1)
  • if you are using a non-English version of Windows, you must first install the English Language Pack.
Also, Microsoft states that to install Windows PowerShell Integrated Scripting Environment (ISE) for Windows PowerShell 3.0 on computers running Windows Server 2008 R2 with Service Pack 1, before installing Windows Management Framework 3.0 RC, you have to use Server Manager to add the optional Windows PowerShell ISE feature to Windows PowerShell. Personally I didn't do it and the feature got installed by PowerShell itself, so why bother?



If you don't have the .NET Framework 4 installed on your Server 2008 R2 but you try to install it you'll get a “The update is not applicable for your system” message box:



If you are unsure about the .NET version you own, check whether the registry key HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full contains the 'Install' registry entry with a value of 1. If so, then .NET 4 is already there.

In a fresh Windows 2008 R2 without Service Pack 1 you will find that:
  • the key for .NET is called: HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727 
  • the output of (get-host).version telling your current PowerShell version is: 'Version : 2.0'
  • the build of WM, retrieved with gwmi -class Win32_WMISetting, is '7600.16385'

After installing SP1, one value changes:
  • gwmi -class win32_wmisetting returns '7601.17514'
After installing .NET 4
  • a new key for .NET 4 is added: HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4
A last check to PowerShell 2.0 features in order to compare later:
  • (gcm).count returns 410
  • (get-alias).count returns 137
  • (Get-Module -ListAvailable).count returns 7
  • (Get-PSSnapin).count returns 7
Now let's run the PowerShell installer, Windows6.1-KB2506143-x64:

Complete the installation and restart.

Once the server is restarted, launch PowerShell and you'll immediately see that it has upgraded to version 3.0 by querying the $host variable:

$host

Name : ConsoleHost
Version : 3.0
InstanceId : b1ace04c-20a5-4560-a6d5-37d4fc74b37c
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture :en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxyIsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

Let's count the available cmdlets, aliases, modules and snapins:
  • (gcm).count returns 366
  • (get-alias).count returns 148
  • (Get-Module -ListAvailable).count returns 18
  • (Get-PSSnapin).count returns 1
Apparently there are less cmdlets in PowerShell 3.0 than in 2.0 but this is false. In V2 gcm (alias for get-command) returns cmdlets, functions and aliases, while in V3 it returns cmdlets and functions only.

In reality there are 236 cmdlets in V2 (the right query for V2 is '(gcm -CommandType cmdlet).count') and 313 in V3.

I hope you have found this post interesting. I will talk a litlle more about new cmdlets in V3 in a future post. Stay tuned!

10 comments:

  1. I had .Net 4 previously installed, but had to run a repair before PowerShell 3.0 would install.

    ReplyDelete
  2. Thnaks for sharing Minkah. Is this the command-line that you used, right?

    %windir%\Microsoft.NET\Framework64\v4.0.30319\SetupCache\Client\setup.exe /repair /x86 /x64 /ia64 /parameterfolder Client /q /norestart

    ReplyDelete
  3. Upgrade System Center Configuration Manager 2012 to SP1 before... Otherwise - good luck with fixing SCCM...

    ReplyDelete
  4. Thanks for this procedure! I updated my servers and everything went straightforward!
    Al

    ReplyDelete
  5. How to auto install NET4.5, PowerShell 3.0, KB2592525 (PowerShell)

    http://gallery.technet.microsoft.com/scriptcenter/How-to-auto-install-NET45-bdb4bf1f

    ReplyDelete
  6. Thanks mate for this procedure, I am new to Powershell and your blog helps alot!!!

    ReplyDelete
    Replies
    1. Welcome to the Powershell world then!
      Carlo

      Delete
  7. Actually, with the $host variable you find out only the version of the powershell-host (The console, or ISE, or...). The host is just what communicates with the powershell engine(!) (Powershell.exe) and can have a different version as the powershell engine.
    To query the actual version of the powershell.exe query "$PSVersionTable.psversion" instead.

    ReplyDelete
    Replies
    1. Thanks, you're right, I was a little quick on this. $PSVersiontable is the right way to check for your current Powershell version.

      Delete
  8. Very useful article. Nice, thanks :) After a hole day try to find out what wrong. Found from you article that I must to have SP1 update pack. Thanks again :)

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...