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:

Enable-PSRemoting -force
WinRM has been updated to receive requests.
WinRM service started.

Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150858770" M
achine="blabla.local"><f:Message>The client cannot connect to the destination specified in the request. Verify
 that the service on the destination is running and is accepting requests. Consult the logs and documentation for the W
S-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, r
un the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". </f:Messag
e></f:WSManFault>

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

gsv winrm

Status   Name               DisplayName
------   ----               -----------
StopP... winrm              Windows Remote Management (WS-Manag...

PS C:\Windows\system32> gsv winrm | Restart-Service -force
Restart-Service : Service 'Windows Remote Management (WS-Management) (winrm)' cannot be stopped due to the following er
ror: 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:

$id = gwmi Win32_Service -Filter "Name LIKE 'WinRM'" | select -expand ProcessId
Stop-Process -Id $id -Force
gsv winrm | start-service
gsv winrm

Status   Name               DisplayName
------   ----               -----------
Running  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.

$type = (gsv)[0].status.gettype().FullName
Get-EnumValue $type

Name            Value Binary Hex
----            ----- ------ ---
Stopped             1 1      1
StartPending        2 10     2
StopPending         3 11     3
Running             4 100    4
ContinuePending     5 101    5
PausePending        6 110    6
Paused              7 111    7

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