Stop-Service Cmdlet not able to open service that exists

陌路散爱 提交于 2020-01-03 06:59:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!