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?
Method 3: Using PowerShellGet-Service -ComputerName computername -Name servicename | Restart-Service -Force. Get-Service -ComputerName computername -Name servicename | Stop-Service -Force.
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.
To stop multiple services can be stopped using Name or displayname by providing command (,) between them.
Solution was to run PowerShell as an administrator. Stop-Service worked ok after doing that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With