I have multiple windows service and there are no dependencies between them. I want to stop all the windows services at the same time. I don't want to stop all the services one by one. How can I achieve this?


The -name parameter of the Stop-Service command is an [array strings][1]. You can pass multiple services to it.

Stop-Service -name service1,service2,service3


[string[]]$services = @('service1', 'service2')
Stop-Service -Name $services -NoWait
while ((Get-Service -Name $services | Where-Object { $_.status -ne 'Stopped'}).Count -ne 0)
    Start-Sleep -Seconds 5
  • I have tried this command, but it's not stopping services at the same time. I am getting below output. WARNING: Waiting for service 'MyFirstService1 (MyFirstService1)' to stop... WARNING: Waiting for service 'MyFirstService1 (MyFirstService1)' to stop... – ankit thakkar Feb 21 '20 at 6:59
  • @ankitthakkar - I misunderstood your requirement. In that case, you can not use Stop-Service like this. You'd have to wrap each stop service in a job or async procedure but even then, you can never be sure they all stop at the exact same time. Each will get a stop command at around the same time though. – Lieven Keersmaekers Feb 21 '20 at 7:54
  • I am using the stop-service command to stop all the service by using -NoWait but I also want that it will not move to the next step till all services will stop. – ankit thakkar Feb 21 '20 at 8:51
  • In that case, you can write a loop to check if all services are stopped. I have added this to my answer – Lieven Keersmaekers Feb 21 '20 at 9:34
  • I have resolved this using loop and WaitForStatus Argument of service. – ankit thakkar Feb 21 '20 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.