rotemp
rotemp

Reputation: 61

Invoke-Command failed: WinRM cannot complete the operation

Using 2 machines, a local and a remote (with an address marked as remoteAddress), I'm trying to run this on the local machine:

Invoke-Command -ComputerName remoteAddress -ScriptBlock { dir c:\ }

but I get this error:

[remoteAddress] Connecting to remote server remoteAddress failed with the
following error message : WinRM cannot complete the operation. Verify that
the specified computer name is valid, that the computer is accessible over
the network, and that a firewall exception for the WinRM service is enabled
and allows access from this computer. By default, the WinRM firewall exception
for public profiles limits access to remote computers within the same local
subnet.
For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (remoteAddress:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken

I followed fixes to similiar situations. What I've checked:

But still, I get this error trying to connect to the remote machine.


I ran test-wsman -ComputerName _remote-machine_ -Port 5985 from my local-machine And I got this error:

test-wsman : WinRM cannot complete the operation. Verify that the specified computer
name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service
is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits
access to remote computers within the same local subnet. 
At line:1 char:1
+ test-wsman -ComputerName _remote_ -Port 5985
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (_remote-machine_:String) [Test-WSMan], InvalidOperationExcept
   ion
    + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.TestWSManCommand

Upvotes: 1

Views: 24628

Answers (5)

IgorG
IgorG

Reputation: 1

Check your WinRM proxy settings by running following cmd command: netsh winhttp show proxy

By default WinRM send messages directly and do not uses proxy (https://learn.microsoft.com/en-us/windows/win32/winrm/proxy-servers-and-winrm) In my case on this one host where I had exactly the same issue with Invoke-Command (same error msg) proxy was configured. You can remove proxy or in this case reset WinRM configuration to default with the following cmd command: netsh winhttp reset proxy

That did the trick for me!

Upvotes: 0

Mark
Mark

Reputation: 1112

IPv4 FilterEnsure that the IPv4 filter in the (enabled) "Allow remote server management through WinRM" policy setting is complete, either with an asterisk * if this is appropriate, or otherwise with a list or range of IP addresses. Leaving it blank will result in this message.

Upvotes: 0

NARENDER
NARENDER

Reputation: 11

Make sure your NetConnectionProfile should be Private. enter image description here

And here is the reason for the public profile. enter image description here

In my case, it got worked after changing NetConnectionProfile as Private from Public. I hope this works for you.

Upvotes: 0

Smorkster
Smorkster

Reputation: 357

Do you have an active remote session, like Remote Desktop, to the computer?

I have experienced that that can be the only reason for Invoke-Command to fail.

Upvotes: 0

Moerwald
Moerwald

Reputation: 11254

Did you add the remotes to your local trusted host list? If not you can add them via

winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'

Upvotes: 0

Related Questions