Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Cannot Be Stopped - Error stopping remote Winodws Service using Powershell

I have a simple script that stops/starts multiple services on remote server. It works fine but every other run I see following error. But even though it says it cannot stop the service actually it stopping it. I tried adding some pause time between different services but this doesn't seem to help.

This is how it's stopping the service

Get-Service -ComputerName SERVER1 -Name SERVICE1 | Stop-Service -Force

And this is full error

Stop-Service : Service 'SERVICE1 (SERVICE1)' cannot be stopped due to the following error: Cannot
stop SERVICE1 service on computer 'SERVER1'.
At C:\Script\dev1_stop.ps1:25 char:67
+ ... puterName SERVER1 -Name SERVICE1 | Stop-Service -Force
+                                                       ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Stop-Service],
   ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.StopServiceCommand
like image 487
jackrobot Avatar asked Nov 27 '25 02:11

jackrobot


1 Answers

I would say that it is likely something specific to the service and/or its dependencies. Since I am unfamiliar with "SERVICE1", I can't really provide a better response. You might look in the System event log on the failed host(s).

like image 69
Dustin Avatar answered Nov 29 '25 23:11

Dustin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!