简体   繁体   中英

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM