I have a SQL job whose step of 'PowerShell' type does 'exit 1' if encounters an error i.e.

$ErrorActionPreference='stop'; trap{"$_"; exit 1}

Problem is, SQL Server doesn't pay attention to that exit code, and reports "The step did not generate any output. Process Exit Code 0. The step succeeded."

Any idea how to successfully tell SQL Server from a PowerShell step that something went wrong?

Thanks in advance.

link|improve this question

27% accept rate
feedback

1 Answer

throw "Failure" will work. See this MSDN forum post for additional information:

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.