Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop-Service Cmdlet not able to open service that exists

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?

like image 932
ricky89 Avatar asked Mar 19 '15 14:03

ricky89


People also ask

How do I stop a PowerShell service from the remote server?

Method 3: Using PowerShellGet-Service -ComputerName computername -Name servicename | Restart-Service -Force. Get-Service -ComputerName computername -Name servicename | Stop-Service -Force.

How do I restart a service in PowerShell?

Start-Service (Microsoft.PowerShell.Management) - PowerShell The Start-Service cmdlet sends a start message to the Windows Service Controller for each of the specified services. If a service is already running, the message is ignored without error.

How do I stop multiple services in PowerShell?

To stop multiple services can be stopped using Name or displayname by providing command (,) between them.


1 Answers

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

like image 182
ricky89 Avatar answered Nov 15 '22 23:11

ricky89