This page looks best with JavaScript enabled

How to kill a service stuck in pending state.

 ·  ☕ 2 min read  ·  ✍️ Javy de Koning

WinRM ‘StopPending’ issues

Recently I logged into a machine and ran ‘Enable-PSRemoting -Force’ to end up with error code ‘2150858770’. WinRM service was in ‘StopPending’ state:

 1Enable-PSRemoting -force
 2WinRM has been updated to receive requests.
 3WinRM service started.
 5Set-WSManQuickConfig : <f:WSManFault xmlns:f="" Code="2150858770" M
 6achine="blabla.local"><f:Message>The client cannot connect to the destination specified in the request. Verify
 7 that the service on the destination is running and is accepting requests. Consult the logs and documentation for the W
 8S-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, r
 9un the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". </f:Messag

So upon checking I found that the WinRM service was having issues:

1gsv winrm
3Status   Name               DisplayName
4------   ----               -----------
5StopP... winrm              Windows Remote Management (WS-Manag...
7PS C:\Windows\system32> gsv winrm | Restart-Service -force
8Restart-Service : Service 'Windows Remote Management (WS-Management) (winrm)' cannot be stopped due to the following er
9ror: Cannot stop winrm service on computer '.'.

Solution, force kill the service.

All-right so what can we actually do to kill this? Behind a service is actually a process with a unique PID. Let’s get the PID of the process and kill the process instead:

1$id = gwmi Win32_Service -Filter "Name LIKE 'WinRM'" | select -expand ProcessId
2Stop-Process -Id $id -Force
3gsv winrm | start-service
4gsv winrm
6Status   Name               DisplayName
7------   ----               -----------
8Running  winrm              Windows Remote Management (WS-Manag..

Tada, problem resolved!

Bonus: enumerate dotnet type to find possible service status values.

Use Get-EnumValue to enumerate the dotnet object.

 1$type = (gsv)[0].status.gettype().FullName
 2Get-EnumValue $type
 4Name            Value Binary Hex
 5----            ----- ------ ---
 6Stopped             1 1      1
 7StartPending        2 10     2
 8StopPending         3 11     3
 9Running             4 100    4
10ContinuePending     5 101    5
11PausePending        6 110    6
12Paused              7 111    7

Javy de Koning
Javy de Koning
Geek 🤓, Love sports 🏃‍♂️🏋️‍♂️, Food 🍛, Tech 💻, @Amsterdam ❌❌❌.