I am trying to execute Powershell command remotely, my problem is that the Powershell is used is version 4.0, and I want to execute my command remotely using Powershell Core 6.0.4.
I tried to use this command on the remote host
Set-PSSessionConfiguration -name microsoft.powershell -psversion 6.0 -FORCE
And getting this error:
Set-PSSessionConfiguration : Cannot bind parameter 'PSVersion' to the target. Exception setting "PSVersion": "The
value 6.0 is not valid for the PSVersion parameter. The available values are 2.0,3.0 and 4.0."
I got version 6.0.4 installed on my remote machine.
I know it uses version 4 to execute my remote command, because
Invoke-Command -Session $session -ScriptBlock {$PSVersionTable.PSVersion};
returns:
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
4 0 -1 -1 IIS-DEV2
Any ideas how to force it to use version 6?
As shown in your answer, obsolete PowerShell Core versions indeed require running Install-PowerShellRemoting.ps1
in order to enable a given computer to act as remoting endpoint (i.e., to allow other computers to target it with remoting cmdlets such as New-PSSession
or Invoke-Command
), said script was a stopgap that is no longer needed in current PowerShell Core versions.
The installation script is a short-term solution until we add additional functionality to Enable-PSRemoting to perform the same action.
Enable-PSRemoting
cmdlet, as in Windows PowerShell.Note: As of this writing, WS-Management (WSMan) Remoting in PowerShell Core doesn't yet mention that the current 6.x version no longer needs the stopgap script - see this GitHub issue. Also note that Enable-PSRemoting
is not available on Unix-like platforms as of v7.0 (and neither is the obsolete Install-PowerShellRemoting.ps1
script).
As an aside re targeting a specific PowerShell Core version:
While -ConfigurationName Powershell.6.0.4
does work if you want to target a very specific version, Enable-PSRemoting
also creates a PowerShell.<OwnMajorVersionOnly>
configuration that doesn't require your to specify the full version number (which is likely to change, as you update PowerShell Core on the endpoint machine).
Therefore, consider using the following instead, using the example of having run Enable-PSRemoting
from a PowerShell 7.x version on the remoting endpoint:
-ConfigurationName PowerShell.7
For more information, see this post.