PowerShell script won't run as local user or administrator

41 Views Asked by At

I have a very small PowerShell script to reboot a given service. Unfortunately, I'm unsure why it's not working properly. It is executable, but it won't stop the requested service; neither is it executing the functions on the other 2 lines.

Here's the script:

# Stop the "serviceName" service
Stop-Service -Name "serviceName" -ErrorAction SilentlyContinue

# Wait for 10 seconds
Start-Sleep -Seconds 10

# Start the "serviceName" service
Start-Service -Name "serviceName"

I tried to execute the script from my .\Users\me\Desktop\ using PowerShell running as admin, with no luck.

1

There are 1 best solutions below

0
Juan On

removing "-ErrorAction SilentlyContinue" from the second line worked.