31

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?

2
  • 3
    Ignore me I was being thick. Had to run as an admin. Works fine now. Commented Mar 19, 2015 at 14:09
  • 1
    Change the title ("not able to open" instead of "find") and answer the question yourself Commented Mar 19, 2015 at 14:23

1 Answer 1

49

Solution was to run PowerShell as an administrator. Stop-Service worked ok after doing that.

Sign up to request clarification or add additional context in comments.

2 Comments

This worked thanks. But does anyone have an idea how to make it not require the PS console ran as Administrator?
@tolache. You have two options. When the powershell is open rightclick on the taskbar icon and select 'run as administrator'. Or use this super fancy shortcut: windows-x, a

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.