Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run remote Powershell session as version 2

I'm on a server that is running Powershell Version 2:

PS C:\> $PSVersionTable

Name      Value
----      -----
...
PSVersion 2.0

I then create a new remote session to a different 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 to be in Version 2 for my script so I enter a session (to make it easier). I then 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 enter anything else into the console until I Ctrl-C).

I've also tried going through the Invoke-Command:

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

and it does the same.

I've also tried to register a PSSessionConfiguration as per 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 of what I can try next?! Thanks

like image 313
Pete Avatar asked Nov 06 '15 03:11

Pete


1 Answers

On what machine did you run Register-PSSessionConfiguration?. Your computer or the "server"?

You need to make the configuration on the target server. That is what you will be running the hosted PSSessionConfiguration.

I just tried the steps in the technet article and it worked perfectly. My 2008 server remoted to my windows 7 machine running a 2.0 PSSessionConfiguration.

On target server/host:

Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0

Then, on the client machine, reference the 'PS2' configuration.

$s = New-PSSession -ComputerName Server01 -ConfigurationName PS2
like image 180
Matt Avatar answered Oct 20 '22 07:10

Matt