Set-Service: Cannot stop service because it is dependent on other services

Wolfgang picture Wolfgang · Oct 1, 2016 · Viewed 13.4k times · Source

When I run the following command:

Set-Service -ComputerName appserver -Name MyService -Status Stopped

I get an error message:

Set-Service : Cannot stop service 'My Service (MyService)' because it is
dependent on other services.
At line:1 char:12
+ Set-Service <<<<  -ComputerName appserver -Name MyService -Status Stopped
    + CategoryInfo          : InvalidOperation: (System.ServiceProcess.ServiceController:ServiceController) [Set-Service], ServiceCommandException
    + FullyQualifiedErrorId : ServiceIsDependentOnNoForce,Microsoft.PowerShell.Commands.SetServiceCommand

I can stop the service from the services.msc GUI, and I can start the service with Set-Service, but I can't stop it again.

It is true that the service depends on some other services, but I don't understand why that would prevent me from stopping it—nothing else depends on it.

Answer

Ansgar Wiechers picture Ansgar Wiechers · Oct 2, 2016

The Set-Service cmdlet is for changing the configuration of a service. That you can use it to stop a service by changing its status is just coincidental. Use the Stop-Service cmdlet for stopping services. It allows you to stop dependent services as well via the parameter -Force. You'll need to retrieve the service object with Get-Service first, though, since Stop-Service doesn't have a parameter -ComputerName.

Get-Service -Computer appserver -Name MyService | Stop-Service -Force