I have a few different services installed on the same machine. I'm writing a PowerShell 2 script to start and stop them.
For some of the services, I can use Start-Service -displayname "the service"
to successfully start it. On others, using the Start-Service
cmdlet causes and error along the lines of "Cannot start service ... on computer '.'".
In the cases that I get an error using the Start-Service
cmdlet, sc start "the service"
always succeeds.
Vice versa is also true (although sc start
doesn't return any errors--it just doesn't start the service at all.)
Is there any difference between these commands? Is there an alternative command I should be using? Finally, can I 'catch' any errors from the cmdlet and just include both commands to cover all the bases?
This problem is repeatable for me, even if I uninstall and reinstall the service.
Thanks!