Run PowerShell in Version 2 While PowerShell V3 RC Is Installed

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

$psversiontable

image

Version 2 using $psversiontable

powershell.exe -Version 2
$psversiontable

image

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

image

Invoke-RestMethod with V2

powershell.exe -Version 2
Invoke-RestMethod -Uri http://blogs.msdn.com/b/powershell/rss.aspx |
Select Title

image

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

image

V2 – Number of cmdlets with –Version 2 switch

powershell.exe -Version 2
Get-Command -type cmdlet | measure-object

image

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.

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell, V3 and tagged , , . Bookmark the permalink.

4 Responses to Run PowerShell in Version 2 While PowerShell V3 RC Is Installed

  1. PeterVermont says:

    Similar to @crshnbrn66 I do not think it is working when my default is Powershell 5 and I invoke powershell -Version 4.0:

    PS C:\Parabon\Crush\samples\mdr> $PSVersionTable.PSVersion

    Major Minor Build Revision

    5 0 10586 122

  2. crshnbrn66 says:

    This process works well with 3,4,5 to version 2. But if you try it with Version 3.0 and have 5.0 it shows 5.0 in your version table. Am I missing something?

    PS C:\Windows\system32> $psversiontable
    Name Value
    —- —–
    PSVersion 5.0.10514.6
    WSManStackVersion 3.0
    SerializationVersion 1.1.0.1
    CLRVersion 4.0.30319.42000
    BuildVersion 10.0.10514.6
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion 2.3
    PS C:\Windows\system32> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 3
    Windows PowerShell
    Copyright (C) 2015 Microsoft Corporation. All rights reserved.
    PS C:\Windows\system32> $psversiontable
    Name Value
    —- —–
    PSVersion 5.0.10514.6
    WSManStackVersion 3.0
    SerializationVersion 1.1.0.1
    CLRVersion 4.0.30319.42000
    BuildVersion 10.0.10514.6
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion 2.3

  3. Doug says:

    So is there no way to run Powershell v2 with the .NET 4 CLR? Before I installed PS v3, I was able to do this via the powershell.exe.config file by adding support for .NET 4.0. But now that I have installed the release version of Powershell v3, anytime the .NET 4.0 CLR is used, it forces PS v3 to be loaded. I now can ONLY use PS v2 with .NET 2.0. Is there anything I can do here? I have modules that depend on .NET 4.0.

  4. Pingback: Episode 192 – Eric Williams from Cisco on the UCS PowerTool « PowerScripting Podcast

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s