Invoking a PowerShell script that exits with a non-zero code does not mark the task as failed.
E.g., simply running a .ps1 with
Exit 1
has the following output reported in the logs
Deployment status for machine '<hostname>:5985' : 'Passed'
The regular _PowerShell_ task with an inline script marks the task as failed as expected.
I'd also like to be able to fail a task by non-zero exit code
@shaykalyan , @NikolayKash , thanks much for reporting the issue. This behavior is by design.
We consider your feedback and will try to address it in future releases.
i have the same problem, I am running some webtest using powershell on target machine. It passes the task even when the tests are failed. Is there a work around for this. Thanks.
@psutharsan: Not a very clean work around, but since the default $ErrorActionPreference is set to "Stop", writing to the Error stream in your script via Write-Error will be terminal and result in the task being marked as failed.
@pavanadepu2: I'm curious why the design is such?
@ericsciple @pavanadepu2 @mvvsubbu @RoopeshNair - Can you please confirm if the exit code is now returned with merge #5606?
nope that pr is for the powershell task
Thank you for your feedback. This should be fixed now. The latest version supports additional error handling options as well.

Most helpful comment
@psutharsan: Not a very clean work around, but since the default $ErrorActionPreference is set to "Stop", writing to the Error stream in your script via
Write-Errorwill be terminal and result in the task being marked as failed.@pavanadepu2: I'm curious why the design is such?