2014-04-17 32 views
0

我有這樣的預部署PowerShell腳本運行:章魚部署PowerShell的默默似乎繼續不上班

sc.exe stop "someservice" -ErrorAction SilentlyContinue 

我期待,如果它存在的someservice將被停止,如果它不」噸,錯誤將被吞噬。

但是,當我推出新服務時,出現錯誤,提示服務未找到。

Inb4 - 服務需要以特殊方式安裝(第三方服務),所以我不能使用章魚部署的服務安裝程序。

回答

2

你沒有得到預期結果的原因是因爲sc.exe不是powershell cmdlet,而是windows服務器程序。相反,使用stop-service cmdlet的

Stop-Service -Name ServiceName -Force -ErrorAction SilentlyContinue

get-help stop-service -online