We have a PowerShell script that restarts a service on another computer. When we use PowerShell's built-in service control cmdlets, like so:
$svc = Get-Service -Name MyService -ComputerName myservicehostname
Stop-Service -InputObject $svc
Start-Service -InputObject $svc
We get this error back:
Stop-Service : Cannot open MyService service on computer 'myservicehostname'.
However, when we use sc.exe, like so:
C:\Windows\System32\sc \\myservicehostname stop MyService
C:\Windows\System32\sc \\myservicehostname start MyService
the start and stop succeed.
The user doing the restarting is not an administrator. We use subinacl to grant the user permissions to start/stop and query the service:
subinacl.exe /service MyService /GRANT=MyServiceControlUser=STO
How come PowerShell can't stop my service but sc.exe
can?