Pergunta

I have this pre-deploy powershell script running:

sc.exe stop "someservice" -ErrorAction SilentlyContinue

I'm expecting that the someservice will be stopped if it exist, and if it doesn't, the error will get swallowed.

However, when I push a new service out, I get an error saying the service isn't found.

Inb4 - The service needs to be installed in a special way (a third party service), so i can't use octopus deploy's service installer.

Foi útil?

Solução

The reason why you are not getting the desired result is because sc.exe is not a powershell cmdlet, it is a windows server program. Instead, use the stop-service cmdlet

Stop-Service -Name ServiceName -Force -ErrorAction SilentlyContinue

get-help stop-service -online

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top