How to change Powershell CLR version when running

2019-06-16 07:35发布

问题:

I've got a problem trying to run some of our scripts on a remote server.

We need all Powershell sessions to load v4 of the CLR, as we're loading in our own custom binaries with our scripts.

We've been doing this for some time (we do so using a modified powershell.exe.config similar to here: How can I run PowerShell with the .NET 4 runtime?), and all is well when you RDP into 'Server1' and open a Powershell session. The variable $PSVersionTable tells us that the CLR v4 is loaded.

Now that we're trying to streamline things by running these commands remotely we run into our problem: when you enter a remote Powershell session into the same server, $PSVersionTable shows only v2...

So the problem is that if you open a local Powershell session on Server1 it loads v4, but if you remote from Server2 to Server1 it only loads v2.

Anybody know how to tell Powershell to use CLR v4 for remote sessions? Any help would be much appreciated!

回答1:

Try creating a c:\windows\System32\wsmprovhost.exe.config file and a c:\windows\SysWOW64\wsmprovhost.exe.config file in 64bit OS like this:

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
         <supportedRuntime version="v4.0.30319"/>        
         <supportedRuntime version="v2.0.50727"/>        
    </startup>
</configuration>