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).

  • In simply, could you please tell us that what is your purpose of forcing the task sequence to fail?
    – Jimmy Sun
    Feb 23 '17 at 8:52
  • Have you tried to run a command line with just "exit 1" inside?
    – Narcis
    Mar 8 '17 at 12:47

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.

  • Thanks! I was thinking along the lines of putting in a hardware check that was guaranteed to fail (like a 10GHz CPU), but your solution is much more elegant. Also, I tested it and it works.
    – Wes Sayeed
    Mar 16 '17 at 18:14
  • Additionally, I have to use a task sequence in this scenario because the application has many components, some of which may already be installed on some PCs, and some versions of those components that must be uninstalled first before reinstalling their newer versions; too much for a normal application deployment to handle even with dependencies. Most of this decision-making happens within VBScripts that I've written at the component level. If I'd known about the Powershell App Deployment Kit, I might've used it :-) As it stands, I basically invented my own version of it.
    – Wes Sayeed
    Mar 16 '17 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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