MCPMag.com

Sign up for our newsletter.

I agree to this site's Privacy Policy.

Prof. Powershell

PowerShell 2 and 3, Side by Side

Here's something nifty: you don't have uninstall PowerShell 2 to use version 3.

When I was a kid I often heard my mom singing, "Just to travel along, singing a song, side by side." It is still a catchy tune, but you're probably wondering what this has to do with PowerShell. Well, when PowerShell 2.0 came out, if you wanted to run it you had to install it in place of PowerShell 1.0. There was no provision for running the two versions on the same box, no "side by side." Generally, this wasn't a problem because of backwards compatibility. But many would have preferred a side-by-side installation.

Now we have PowerShell 3.0, which is in CTP2 as of this writing. This version has been architected so that you can in effect run versions 2.0 and 3.0 side by side. PowerShell 1.0 has left the building, despite the fact that the install path still reflects 1.0:

PS C:\> $pshome
C:\Windows\System32\WindowsPowerShell\v1.0

For the most part, that doesn't really matter. What does matter is that now you can start a PowerShell 2.0 session on a machine running PowerShell 3.0. You can test it like this. If you have 3.0 installed, take a look at the $PSVersionTable variable:

PS C:\> $psversiontable

Name                       Value
----                       -----
WSManStackVersion          3.0
PSCompatibleVersions       {1.0, 2.0, 3.0}
SerializationVersion       1.1.0.1
BuildVersion               6.2.8158.0
PSVersion                  3.0
CLRVersion                 4.0.30319.239
PSRemotingProtocolVersion  2.103

Notice the PSVersion property. To "switch" to PowerShell v2.0, all we need to do is start a new instance and specify the version. We can do this right from the current PowerShell prompt.

PS C:\> powershell -version 2.0
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\> $psversiontable

Name                       Value
----                       -----
CLRVersion                 2.0.50727.5448
BuildVersion               6.1.7601.17514
PSVersion                  2.0
WSManStackVersion          2.0
PSCompatibleVersions       {1.0, 2.0}
SerializationVersion       1.1.0.1
PSRemotingProtocolVersion  2.1

The PSVersion property has changed. Did you also notice the copyright notice? That is right out of v2.0. I can run all the commands and scripts I want and they will run in a PowerShell 2.0 session. I cannot access v3.0 features.

PS C:\> update-help
The term 'update-help' is not recognized as the name of a cmdlet, function, scr
ipt file, or operable program. Check the spelling of the name, or if a path was
 included, verify that the path is correct and try again.
At line:1 char:12
+ update-help <<<<
+ CategoryInfo          : ObjectNotFound: (update-help:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Although I can still see thinks like v3.0 About files. When I'm finished, I simply type Exit. If you think you need to use v2.0 often, create a new shortcut on your desktop or Start menu to execute powershell.exe -version 2.0. You can get additional options from command help:

C:\> powershell -?

Note: This information is based on PowerShell 3.0 CTP 2 which is subject to change, and most likely will, prior to release.

About the Author

Jeffery Hicks is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with over 20 years of experience, much of it spent as an IT consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant. Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular contributor to the Petri IT Knowledgebase and 4SysOps. If he isn't writing, then he's most likely recording training videos for companies like TrainSignal or hanging out in the forums at PowerShell.org. Jeff's latest books are Learn PowerShell 3 in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches and PowerShell in Depth: An Administrators Guide. You can keep up with Jeff at his blog http://jdhitsolutions.com/blog, on Twitter at twitter.com/jeffhicks and on Google Plus (http:/gplus.to/JeffHicks)

comments powered by Disqus

Reader Comments:

Wed, Oct 24, 2012 Jim T Canada

Hello, I have some powershell 2.0 scripts. Will they run as is on powershell 3.0 in Windows 8 ? Many thanks, Jim

Sun, May 27, 2012 Shiju Samuel

Hi Jeffery, Thanks, one question though Is it possible to run powershell_ise for 3.0 with powershell 2.0 underneath? I really like the 3.0 interface but worried to run it on still CTP in production. -Thanks Shiju

Fri, Jan 6, 2012 Bryan Price Jacksonville, FL, USA

I installed the 3.0 CTP, had some issues, uninstalled, tried to reinstall, which won't know (sigh). If I had known this (the -version argument, not that it would have been a pain to get 3.0 installed again...), I wouldn't have uninstalled 3.0! Doesn't matter, this computer needs to be reinstalled for other issues, I'm holding out to just put Win 8 Beta on it, instead of Win 7.

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above