Many of you have downloaded the latest build of PowerShell V3 (currently in RC). While PowerShell V3 is amazing, you might have wondered how you can run some scripts or other things with PowerShell V2 that are just not working the way you want them to in V3. Given that V3 loads side by side with V2, there must be a way to get this to work without having to uninstall V3 and re-install V2…
Well, you are in luck because there is a simple switch that you can add with PowerShell.exe. The switch is: –Version 2.
Simple, isn’t it?
Don’t believe that it works yet? Here are some examples to make a believer out of you.
Version 3 using $psversiontable
Version 2 using $psversiontable
powershell.exe -Version 2 $psversiontable
Notice that the PSVersions are in fact different and match what the version should be. Also notice that the CLR versions are completely different (V3 uses .Net 4.0 while V2 uses 2.0).
Once last example. You know some of the great new commands with V3 or even some commands such as Invoke-RestMethod or old commands you know and love such as with great new parameters such as –Tail on Get-Content. Well, take a look at the number of cmdlets available in V3 and V2 and you will see that all of the new commands in V3 are not available in V2.
Invoke-RestMethod with V3
Invoke-RestMethod -Uri http://blogs.msdn.com/b/powershell/rss.aspx | Select Title
Invoke-RestMethod with V2
powershell.exe -Version 2 Invoke-RestMethod -Uri http://blogs.msdn.com/b/powershell/rss.aspx | Select Title
Just like I expected, Invoke-RestMethod is not even recognized while Powershell is running with the –Version 2 switch.
Now for the number of cmdlets visible between the two versions.
V3 – Number of cmdlets
Get-Command -type cmdlet | measure-object
V2 – Number of cmdlets with –Version 2 switch
powershell.exe -Version 2 Get-Command -type cmdlet | measure-object
Definitely a difference in what is available between the versions. So keep that in mind if you happen to use the –Version switch to go V2, otherwise you could be left wondering why some of the V3 commands are not working like you think they should. So a script or module isn’t working just yet under V3, in the same console you can just run powershell.exe –Version 2 and have that script working for you.