How to change Powershell CLR version when running commands remotely?

▼魔方 西西 提交于 2019-12-13 13:00: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>


来源:https://stackoverflow.com/questions/12088055/how-to-change-powershell-clr-version-when-running-commands-remotely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!