问题
I am trying to write a PowerShell script to stop services on the local machine.
When I run the get-service cmdlet it works as expected. When I use the stop-service cmdlet, It errors stating that no service exists with the name I specify. If this was true surely the get-service cmdlet would 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?
回答1:
Solution was to run PowerShell as an administrator. Stop-Service worked ok after doing that.
来源:https://stackoverflow.com/questions/29146784/stop-service-cmdlet-not-able-to-open-service-that-exists