The Stop-Service cmdlet cannot open a service that exists

I am trying to write a PowerShell script to stop the services on the local computer.

When I run the get-service cmdlet, it works as expected. When I use the stop-service cmdlet, it indicates that no service exists with the specified name. If this is true, then the get-service cmdlet will throw the same error.

Get-Service "Service 1" # Returns Service and status Stop-Service "Service 1" # Throws error below: Stop-Service : Service 'Service 1' cannot be stopped due to the following error: Cannot open Service 1 service on computer '.'. 

Is there a trick when using the stop-service cmdlet?

+5
source share
1 answer

The solution was to start PowerShell as an administrator. After that, the Stop-Service worked fine.

+9
source

Source: https://habr.com/ru/post/1215686/


All Articles