How to ignore error in powershell step

short version: how do I get Octopus to ignore an error raised by “net stop” or “net start” during a powershell script? (try/catch doesn’t work)

longer version:

We have a project that has steps that stop and later start a windows service. this service has issues, however, and when we execute “net stop XYZ” or “net start XYZ”, it doesn’t always run clean, and will often return an error message. regardless, the service does eventually stop or start.

so, I’ve written a loop that, after issuing the “net stop” or “net start” command, monitors the service’s status using “Get-Service”, checking every 5 seconds, and proceeding when the service finally stops or starts. that part is working.

however, when the “net stop” or “net start” appear to fail, it outputs a red error messages, and thus the powershell step is reported back to Octopus as Failed, even though it has actually run successfully.

How do I get Octopus to ignore an error raised in the powershell script? (surrounding the “net stop” or “net start” in a try/catch block does not help.)


Hi Mike

Thanks for getting in touch.

What about using Start-Service / Stop-Service in place of your net start / stop calls ?

Then you can do this :

Stop-Service MyService -ErrorAction SilentlyContinue
Before polling for it to be stopped.



This does not work for me. How can i suppress this error?

Tentacle script execution
Error 10:37:15
start-webitem : The service cannot accept control messages at this time.
Error 10:37:15
(Exception from HRESULT: 0x80070425)
Error 10:37:15
At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\61c0488
Error 10:37:15
5-08d1-482a-b43b-df162a4a6a58.ps1:9 char:1
Error 10:37:15

  • Start-WebAppPool $appPoolName -ErrorAction silentlycontinue
    Error 10:37:15

Error 10:37:15
+ CategoryInfo : InvalidOperation: (:slight_smile: [Start-WebItem], COMExcept
Error 10:37:15
Error 10:37:15
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.IIs.PowerShell.Provid
Error 10:37:15
Info 10:37:15
Starting IIS app pool ****
Info 10:37:15

PowerShell exit code: 1

Fatal 10:37:15
PowerShell script returned a non-zero exit code: 1
Tentacle version