How to cause an SCCM task sequence to fail on purpose

sccm

I am installing a rather complex piece of software using a task sequence in SCCM 1607 (aka SCCM 2016). Within the task sequence, I have a try/catch block so I can restore the computer to a working state if the TS fails.

Like so:

Mock Task Sequence

The problem here is that when there is an actual failure within the task sequence, the error handling routine does its job and the task sequence exits gracefully. I'm capturing my own logs within the sequence to reflect the error, but as far as SCCM is concerned, the installation was a success. The user does not receive any kind of notification and the application shows in Software Center as installed even though though it isn't. I have to look at my own logs to get any kind of reporting on the errors, and SCCM will never retry the installation on its own.

How can I force the task sequence to fail as the last step in my error handling block? I want the user to see an error and call the help desk. I also want to be able to see the failure in the SCCM console, and I want to have the TS retry on its own (the old version fails to uninstall if it's in use and almost all of the failures I've seen in testing are because the user logged in and launched it before the TS had a chance to remove it).

Best Answer

To cause a task sequence to fail, you can use a "Run Command Line" task sequence step to execute a command that returns a non-zero1 exit code. For example:

cmd /c exit 1

(Of course, you must also ensure the "Continue on error" check box for the task sequence step is unchecked.)

Indeed, you could replace the 1 above with any other number if you want to use different exit codes to reflect different failure reasons. This would allow you to identify which installations failed for a particular reason.

All this being said, a Task Sequence may not be the best mechanism for this specific use case. Consider deploying this software with an Application (or Package and Program) using the Powershell App Deployment Toolkit. It provides many useful features, including the ability to close applications and prevent users from re-launching them until the installation has completed.


1 Technically, the exit code must be one of the numbers not listed in the "Success codes" field on the Options tab of the task sequence step, which by default are 0 and 3010.