Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

WinRM "can't complete the operation. Verify that the specified computer name is valid": check the name, the port, the service, the listener and the firewall rule

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When a remote command stops with "WinRM can't 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", the client did not get an answer from a WinRM listener at that name. Work from the client outward: does the name resolve, does TCP port 5985 answer, is the service running, does a listener exist, and does a firewall rule admit your address. The last one catches people on a public network, where Microsoft's page says the default exception "limits access to remote computers within the same local subnet".

What the message means

Microsoft's Windows Admin Center page lists that wording as the "General connection error" and says it "usually appears when you're trying to connect using WinRM". It gives four reasons: the name did not resolve in DNS, the server could not be reached at all, firewall rules are not configured for the WinRM service, or the WinRM service is not running or is disabled.

A sibling failure has a code. Microsoft's page on errors from WinRM commands lists "The client cannot connect to the destination specified in the requests" with error number -2144108526, which is 0x80338012, and says "This problem may occur if the Window Remote Management service and its listener functionality are broken." It appears when a command such as winrm e winrm/config/listener is run on the server itself. Our own advice: the two may share a cause, so run the same checks for both.

Two facts from Microsoft's pages shape the checks. By default no WinRM listener is configured, and a running service without a listener cannot receive requests. On client versions of Windows the WinRM service is disabled by default, while on server versions its startup type is Automatic.

Likely causes

Cause What you see How to confirm
The name does not resolve Failure for the name, success for the IP address Test-WSMan fails by name and Test-NetConnection by address reaches port 5985
Network path blocked Port 5985 never answers Test-NetConnection -Port 5985 reports TcpTestSucceeded : False
WinRM service stopped or disabled Common on Windows client editions Get-Service -Name WinRM shows Stopped
No listener Service runs, nothing answers winrm enumerate winrm/config/listener returns no listener
Firewall rule off, or admits only the local subnet Works from the same subnet, fails from another Get-NetFirewallRule and its address filter on the target
Group Policy left ListeningOn empty Microsoft's page says a configuration error in the policy results in an empty value for the ListeningOn property Get-WSManInstance winrm/config/listener -Enumerate shows ListeningOn : {}
Alternate port in use Default port 5985 refused The listener output shows a different port

Prove the cause before changing anything

All of these only read. Run steps 1 and 2 on the client and steps 3 to 6 on the target at its console.

1. Ask the WinRM service for its identity. The page says Test-WSMan "submits an identification request that determines whether the WinRM service is running" on the computer:

Test-WSMan -ComputerName app01.example.com

A good result prints the product vendor and version of the service. A bad result is the message above.

2. Test the TCP port separately. Microsoft's page for Test-NetConnection shows TcpTestSucceeded in its output:

Test-NetConnection -ComputerName app01.example.com -Port 5985

TcpTestSucceeded : True means the network and firewall let the connection through, so look at the listener and the authentication. Our own reading: False means a name, route or firewall fault sits before WinRM.

3. Check the service.

Get-Service -Name WinRM

4. List the listeners. Microsoft's page gives this command, and also winrm get winrm/config for the settings:

winrm enumerate winrm/config/listener

Look for an HTTP listener on port 5985 and an address that fits your network. The default HTTP port for WinRM 2.0 is 5985.

5. List the firewall rules. Microsoft's page shows Get-NetFirewallRule -Name 'WINRM*' for the names:

Get-NetFirewallRule -Name 'WINRM*' | Select-Object -Property Name, Enabled, Profile

Rule names differ between Windows versions, and the page says so. Read the remote address of the rule that applies to your profile:

Get-NetFirewallRule -Name 'WINRM-HTTP-In-TCP-PUBLIC' | Get-NetFirewallAddressFilter

6. Look for the empty-listener fault. Microsoft's page says a configuration error in the Group Policy results in an empty ListeningOn value:

Get-WSManInstance winrm/config/listener -Enumerate

Fix

Change one thing, then repeat step 1. A name that does not resolve is a client or DNS matter, and nothing on the target needs to change; correcting a DNS record is outside this page. If the path is blocked and the port test fails from every subnet, ask whoever owns the network device in between.

The service is stopped or disabled

First save the current state, with the startup type in the form Set-Service takes:

Get-CimInstance Win32_Service | Where-Object Name -EQ "WinRM" > winrm-service-before.txt
Get-Service -Name WinRM | Select-Object -Property Name, Status, StartType >> winrm-service-before.txt

Risk: the next two commands change how the WinRM service starts and then start it. Remote management tools that depend on it begin to answer on this computer.

Set the startup type and start the service:

Set-Service -Name WinRM -StartupType Automatic
Start-Service -Name WinRM

Only if you need to back out, and knowing that stopping the service ends remote management sessions on this computer, stop the service, wait until Get-Service -Name WinRM shows Stopped, and then set the startup type back to the StartType value saved in winrm-service-before.txt, which prints in the form Set-Service takes. Microsoft's page says the WinRM service is disabled by default on client versions of Windows, so the saved value may be Disabled; Set-Service accepts Disabled, Manual and Automatic. The StartMode line from Win32_Service in the same file uses other names: Microsoft's Win32_Service page lists its values as Boot, System, Auto, Manual and Disabled, so it is not the value to type; Auto there corresponds to Automatic.

Risk: the first command stops the WinRM service and the second changes how it starts. Remote management sessions that use it end on this computer.

Stop-Service -Name WinRM

Then, once the service shows Stopped:

Set-Service -Name WinRM -StartupType <StartType value from winrm-service-before.txt>

Then run Get-CimInstance Win32_Service | Where-Object Name -EQ "WinRM" and compare it with the saved file.

There is no listener

First save the current state:

winrm enumerate winrm/config/listener > listener-before.txt
Get-NetFirewallRule -Name 'WINRM*' | Select-Object -Property Name, Enabled, Profile > firewall-before.txt
Get-CimInstance Win32_Service | Where-Object Name -EQ "WinRM" > winrm-service-before.txt
Get-Service -Name WinRM | Select-Object -Property Name, Status, StartType >> winrm-service-before.txt
Get-PSSessionConfiguration | Format-List -Property * > psconfig-before.txt

Disruptive step: the next command runs Enable-PSRemoting. Microsoft's page says it starts the WinRM service, sets its startup type to Automatic, creates a listener on any IP address, enables a firewall exception for WS-Management, enables all session configurations, changes the security descriptor of all session configurations to allow remote access, and restarts the WinRM service. Our own reading: the restart ends any remoting session open on this computer. For the listener and the security-descriptor change, the page gives no way to undo it.

Run it in an elevated PowerShell on the target:

Enable-PSRemoting -Force

Microsoft's page says that on a client edition of Windows on a public network the cmdlet refuses unless -SkipNetworkProfileCheck is added, and ties that switch to a rule for the same local subnet only. This page does not tell you to add it.

Only if you need to back out, and knowing that disabling a rule refuses the remote sessions that reach this computer through it, here are the parts that Microsoft's pages let you reverse: disable any firewall rule that firewall-before.txt shows as disabled before, and set the startup type back as in the previous section, using the StartType value in winrm-service-before.txt. Microsoft's session-configuration page describes Disable-PSRemoting as adding a Network_Deny_All entry to the session configurations to "prevent remote users from connecting to the computer, but allow local users"; it is a different change, not a restore of the state in psconfig-before.txt.

Risk: the next command disables a firewall rule. Remote sessions that reach this computer through that rule are refused afterwards.

Run only this line, and only for a rule that firewall-before.txt shows as False:

Set-NetFirewallRule -Name '<rule name from firewall-before.txt>' -Enabled False

The firewall rule admits only the local subnet

Microsoft's page shows Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP-PUBLIC" -RemoteAddress Any, and cautions that the rule's security settings should be checked before it is changed. Our own advice is to name your management subnet instead of Any, because the cmdlet page lists subnets as an accepted format.

First save the current state:

Get-NetFirewallRule -Name 'WINRM-HTTP-In-TCP-PUBLIC' | Get-NetFirewallAddressFilter > address-before.txt

Risk: the next command widens the remote address of a firewall rule. Computers in the subnet you name can then reach the WinRM listener on every network profile that rule covers.

Allow the subnet of the administration host:

Set-NetFirewallRule -Name 'WINRM-HTTP-In-TCP-PUBLIC' -RemoteAddress 198.51.100.0/24

Only if you need to back out, and knowing that computers in the subnet you named are then refused again, set the remote address back to the RemoteAddress value in address-before.txt, typed as the file shows it.

Risk: the next command narrows the rule's remote address again, so computers in 198.51.100.0/24 that reached the listener through it are refused.

Set-NetFirewallRule -Name 'WINRM-HTTP-In-TCP-PUBLIC' -RemoteAddress <value from address-before.txt>

Then run the address-filter command from step 5 again and compare.

Example (illustrative): ci01 at 198.51.100.15 runs Test-WSMan -ComputerName app01.example.com and gets the message. app01, a Windows server at 192.0.2.20 on a public network profile, answers locally: Get-Service -Name WinRM shows Running and the listener shows port 5985. Test-NetConnection -ComputerName app01.example.com -Port 5985 from ci01 reports TcpTestSucceeded : False. The address filter of WINRM-HTTP-In-TCP-PUBLIC shows the local subnet, 192.0.2.0/24, and ci01 is not in it. After the saved copy is made, the administrator allows 198.51.100.0/24, and the same Test-NetConnection now reports True.

Confirm the fix

  1. Test-WSMan -ComputerName app01.example.com prints the service identity instead of the message.
  2. Test-NetConnection -ComputerName app01.example.com -Port 5985 reports TcpTestSucceeded : True.
  3. A real remoting command then reaches authentication. A different error, such as 0x80090322, means the network part is fixed; the SPN and TrustedHosts case is in PowerShell remoting fails with 0x80090322 or asks for TrustedHosts: fix the SPN or use HTTPS, not a wildcard.

What to watch afterwards

  • Microsoft's page says winrm quickconfig creates a firewall exception only for the current profile; if the profile changes, the exception may not apply. Check the rule after a network profile change.
  • Where Group Policy sets the listeners, check ListeningOn after policy changes.
  • Keep the saved files with the change record.

Risks and limits

  • These commands have not been run or lab-tested.
  • Microsoft's pages give no single command that undoes every part of Enable-PSRemoting.
  • Microsoft prints this message with "can't" on the Windows Admin Center page; other tools print variants of it, and the 0x80338012 text is a different sentence.
  • Opening port 5985 to a wide address range exposes remote management; prefer a named subnet, and HTTPS on port 5986 where you can.
  • Microsoft's cmdlet reference pages for the commands above show no update date.

Sources