Launch a Powershell Remote Session as Version 2

I am on a server running Powershell Version 2:

PS C:\> $PSVersionTable Name Value ---- ----- ... PSVersion 2.0 

Then I create a new remote session on another computer and connect to it:

 $sess = New-PSSession -ComputerName {ComputerName} -Credential $credential 

It returns me the result:

 PS C:\> Invoke-Command -Session $sess -ScriptBlock { $PSVersionTable } Name Value ---- ----- ... PSVersion 3.0 

However, I need Powershell for version 2 for my script, so I enter the session (to make it easier). Then I try to get Powershell to be version 2:

 C:\> Enter-PSSession -Session $sess [{ComputerName}]: PS C:\> Powershell -Version 2 Windows Powershell Copyright (C) 2009 Microsoft Corporation. All rights reserverd 

And then it just hangs (or at least never lets me type anything else into the console until there is Ctrl-C).

I also tried using Invoke-Command:

 PS C:\> Invoke-Command -Session $sess -ScriptBlock { Powershell -version 2 } 

and he does the same.

I also tried registering the PSSessionConfiguration, as here: https://technet.microsoft.com/en-us/library/hh847899.aspx

 PS C:\> Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 

But I get:

 Register-PSSessionConfiguration: a parameter cannot be found that matches parameter name 'PSVersion'. 

Does anyone have any ideas what I can try next ?! Thanks

+8
source share
2 answers

What machine did you run Register-PSSessionConfiguration ? Your computer or "server"?

You need to configure on the target server . This is what you will run the PSSessionConfiguration.

I just tried to follow the steps in an article on technology and it worked perfectly. My 2008 server was deleted on my Windows 7 computer with PSSessionConfiguration 2.0.

On the target server / host:

 Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 

Then, on the client machine, specify the "PS2" configuration.

 $s = New-PSSession -ComputerName Server01 -ConfigurationName PS2 
+3
source share

I believe the following does not work:

  #Requires -version 2.0 

Another kluge you can try is to create a scheduled task on the target and execute the task with a script using Powershell.exe -version 2

0
source share

All Articles