1

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?

Dan The Man
  • 1,835
  • 6
  • 30
  • 50
  • `Install-PowerShellRemoting.ps1` should be part of PowerShell Core installation. – user4003407 Aug 23 '18 at 08:42
  • @PetSerAl Didn't understand your answer. I installed powershell core like any other program, what is this script your are talking about, be more specific – Dan The Man Aug 23 '18 at 09:01
  • And like any other program installation it adds some files in your system. Someone among them should be named `Install-PowerShellRemoting.ps1`. – user4003407 Aug 23 '18 at 09:08

2 Answers2

1
  • 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.

  • Current versions of PowerShell Core and all versions going forward should use the 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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
0

In the installation folder of powershell core, there is a script file Install-PowerShellRemoting,

Run the script in the remote server you want the session to, and than when remoting use the following:

$session = New-PSSession -ComputerName IIS-DEV2 -port 5985 -Credential $mycreds -ConfigurationName "powershell.6.0.4"

It worked, and got me a session with Powershell core.

Dan The Man
  • 1,835
  • 6
  • 30
  • 50