I have installed the release version of PowerShell v3 and am having some trouble getting the -Version parameter to work. I have quite a few modules that require .NET 4.0, and I have been using PowerShell v2 without issue using the following powershell.exe.config file:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
This would allow me to run PowerShell v2 with the .NET 4.0 CLR. Everything worked without issue.
I have now installed the release version of PowerShell v3, and anytime I use the command ‘powershell -version 2’ and check the $PSVersionTable variable, it shows that it has loaded PowerShell v3 (with .NET 4.0). If I remove the powershell.exe.config file above and run the same command, it shows that PowerShell v2 is loaded but is using .NET 2.0.
So my question is this: Is there a way to load PowerShell v2 and have it use the .NET 4.0 CLR like I used to do before installing PowerShell v3? Or does PowerShell v3 not allow this?
Also, I should mention why I’m trying to do this – mainly in case there are any incompatibility issues that might crop up when we switch to V3. I plan to test everything with V3, but having the ability to drop back to V2 can save us from a lot of headaches.
What’s happening is the following:
-Version 2Simple, right?!
So what you need to do, if you want to keep PSv2 on .NET 4, is manually disable the publisher policy. This can be done in the app.config file, see a related post here.