0

I'm trying to run a remote command using Invoke-Command over WSMan in PowerShell on my local machine.

Here’s my test script:

$server = 'localhost'
Invoke-Command -Authentication Negotiate -ConfigurationName Powershell.7 -ComputerName $server {
    Write-Host 'hello'
}

However, I get the following error:

OpenError: [localhost] Connecting to remote server localhost failed with the fol
lowing error message : The WS-Management service cannot process the request. Can
not find the Powershell.7 session configuration in the WSMan: drive on the local
host computer. For more information, see the about_Remote_Troubleshooting Help t
opic.

I try enabled remoting:

PS C:\> Enable-PSRemoting -Force
WARNING: PowerShell remoting has been enabled only for PowerShell 6+ configurati
ons and does not affect Windows PowerShell remoting configurations. Run this cmd
let in Windows PowerShell to affect all PowerShell remoting configurations.
WinRM est déjà configuré pour recevoir des demandes sur cet ordinateur.
Set-WSManQuickConfig:
Line |
 121 |                  Set-WSManQuickConfig -force
     |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Erreur :Impossible d'effectuer une ou plusieurs étapes de mise à jour.
PS C:\>

Get-PSSessionConfiguration It returns nothing (no registered endpoints).

🔹 My Question:

How can I register or enable the Powershell.7 endpoint so that I can use Invoke-Command like in the example?

🔹 Additional Info: I’m using PowerShell 7 and old Windows 2012 r2

I’m aware that PowerShell 7 supports SSH remoting instead of WSMan.

However, I want to know if it’s possible to use WSMan remoting with PowerShell 7 (without SSH) or if there's an equivalent supported method to achieve this.

🔹 What I've Tried: I tried registering a session configuration manually:

Register-PSSessionConfiguration -Name 'Powershell.7' -PowerShellVersion '7.0'

But it throws this error:

Register-PSSessionConfiguration: Cannot bind parameter 'PSVersion' to the target
. Exception setting "PSVersion": "PowerShell remoting endpoint versioning is not
 supported on PowerShell Core."

And, this works, but don't use correct version

$server = 'localhost'
Invoke-Command -Authentication Negotiate -ComputerName $server {
    Write-Host 'hello'
}

And, Set-WSManQuickConfig don't work


WinRM Quick Configuration
Running the Set-WSManQuickConfig command has significant security implications,
 as it enables remote management through the WinRM service on this computer.
This command:
    1. Checks whether the WinRM service is running. If the WinRM service is not
 running, the service is started.
    2. Sets the WinRM service startup type to automatic.
    3. Creates a listener to accept requests on any IP address. By default, the
 transport is HTTP.
    4. Enables a firewall exception for WS-Management traffic.
    5. Enables Kerberos and Negotiate service authentication.
Do you want to enable remote management through the WinRM service on this
computer?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
WinRM est déjà configuré pour recevoir des demandes sur cet ordinateur.
Set-WSManQuickConfig: Erreur :Impossible d'effectuer une ou plusieurs étapes de
mise à jour.
PS C:\>

✅ Summary: Is it possible to fix PowerShell 7 with WSMan and Invoke-Command -ComputerName?

If not, is there any supported way to create a WSMan endpoint for PowerShell 7?

0

2 Answers 2

1

Is it possible to use PowerShell 7 with WSMan and Invoke-Command -ComputerName?

Note: The above quote is taken from the original formulation of your question.

Yes, it is generally possible, provided that:

  • your version of PowerShell (Core) 7 is still supported

  • and you're running on a still-supported version of Windows.

If these prerequisites are met:

  • On the target machine, as a one-time configuration operation, run Enable-PSRemoting, which must be run from an elevated PowerShell 7 session.

    • Note that the Install-PowerShellRemoting.ps1 script mentioned in your own answer, while still being distributed with PowerShell (Core) 7 as of v7.5.x, is considered obsolete and has been superseded by Enable-PSRemoting; see the docs.
  • On client machines, pass -ConfigurationName PowerShell.7 to Invoke-Command calls or preset the $PSSessionConfigurationName preference variable to 'PowerShell.7'

    • Perhaps surprisingly, as of PowerShell 7.5.x, PowerShell's remoting cmdlets, such as Invoke-Command, still target a Windows PowerShell remoting endpoint by default; see this answer for more information.

As for your environment:

  • Per the Windows lifecycle information, Windows Server 2012 R2 is out of support (support ended on Oct 10, 2023), which also means that use of still-supported PowerShell 7 versions there isn't supported any longer.

  • Your attempt to run Enable-PSRemoting produced an expected (and benign) warning, but it also produced an unexpected error, which translates to Unable to complete one or more update steps., reported by the Set-WSManQuickConfig cmdlet that is called behind the scenes.

    • Therefore, you did not succeed in setting up a PowerShell 7 remoting endpoint.

    • A Register-PSSessionConfiguration call alone is not sufficient to set up remoting, as it only covers the PowerShell part of the remoting configuration, not also the parts relating to the WinRM service, configuring firewall rules and authentication methods.

    • Given that your environment is unsupported, your only option is to diagnose the specific problem Set-WSManQuickConfig yourself and find a workaround - but note there may not be any.[1]


[1] To perform troubleshooting, compare the configuration steps listed in the confirmation prompt to which of these steps end up successfully implemented after the Set-WSManQuickConfig call reports its error (to ascertain success, compare the state of the machine to that of another where configuration succeeded; per your comment, such other machines do exist).
The status message you're seeing that precedes the error implies that steps 1 and 2 were completed (in the sense that the WinRM services was found to be already properly configured).
Thus, the problem must relate to steps 3 - 5.
The binary Set-WSManQuickConfig's cmdlet's (C#) source code can be found here - though it isn't readily obvious where the specific error message might originate; I suspect it is this line.

Sign up to request clarification or add additional context in comments.

Comments

0

After trying countless things, including reinstalling PowerShell, I found the problem and the solution.

The folder c:\windows\system32\powershell was missing from my computer. Reinstalling PowerShell didn't restore it. To fix it, simply run: Install-PowerShellRemoting.

From that moment on, everything worked as it should.

1 Comment

The c:\windows\system32\powershell folder and its version-specific subfolders are created on demand when Enable-PSRemoting is run from a PowerShell 7 session. If Install-PowerShellRemoting.ps1 inexplicably fixed your problem, you got lucky, but in general you shouldn't rely on this script, because it is obsolete: while it still comes with PowerShell as of v7.5.4, it is no longer documented and during the brief period that it was, it was described as serving as a stopgap until the Enable-PSRemoting cmdlet would be introduced, which has been available for quite a while now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.