Question:
I’m on a server that is running Powershell Version 2:
1 2 3 4 5 6 7 |
PS C:\> $PSVersionTable Name Value ---- ----- ... PSVersion 2.0 |
I then create a new remote session to a different computer and connect to it:
1 2 |
$sess = New-PSSession -ComputerName {ComputerName} -Credential $credential |
It returns me the result:
1 2 3 4 5 6 7 |
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:
1 2 3 4 5 |
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:
1 2 |
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
1 2 |
PS C:\> Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 |
But I get:
1 2 |
Register-PSSessionConfiguration: a parameter cannot be found that matches parameter name 'PSVersion'. |
Does anyone have any ideas of what I can try next?!
Thanks
Answer:
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:
1 2 |
Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 |
Then, on the client machine, reference the ‘PS2’ configuration.
1 2 |
$s = New-PSSession -ComputerName Server01 -ConfigurationName PS2 |