Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Powershell CLR version when running commands remotely?

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!

like image 376
Richiban Avatar asked Aug 23 '12 08:08

Richiban


People also ask

How do I run a specific version of PowerShell?

When you start Windows PowerShell the newest version starts by default. To start Windows PowerShell with the Windows PowerShell 2.0 Engine, use the Version parameter of PowerShell.exe . You can run the command at any command prompt, including Windows PowerShell and Cmd.exe.

How to run PowerShell script remotely?

To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.


1 Answers

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>
like image 158
CB. Avatar answered Oct 21 '22 02:10

CB.