Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 490
Wolfgang Avatar asked Oct 01 '16 20:10

Wolfgang


1 Answers

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
like image 165
Ansgar Wiechers Avatar answered Sep 28 '22 08:09

Ansgar Wiechers