Share via


Meaningful error messages in SCCM OSD Task Sequence

How many times a technician came back to you reading some "4005" generic error back to you expecting your reaction and ability to troubleshoot by this error number? Endless times.

 

We all know you need SMSTS.LOG, a few minutes to find the "real" error somewhere above and only after that you can tell - look! It failed to pre-provision Bitlocker. Or - look! Scanstate failed, let me see its log.

It would be nice if for some steps that we know can fail, we could communicate some error message back to technician, right?

And here is how. (This method will only work for steps of TS that run in Windows PE)

You may noticed, how standard MDT Client template handles errors - there are three top level groups - one your main task sequence flow named "Execute Task Sequence" - with continue on error checked, another is "Cancelled Wizard Group" and another one is "Gather Logs and StateStore on Failure".

So let's say we want to implement meaningful error message for Pre-provision Bitlocker step and fail, showing error message to enable TPM, only on Laptops:

 

  • Group * Enable Bitlocker on Laptops will have a Condition IsLaptop=True
  • Pre-provision Bitlocker is Run Command Line with "Manage-bde -on %OSDisk% -em aes256 -UsedSpaceOnly" and, very important, "Continue On Error".
  • Group Fail on Error will have a condition - _SMSTSLastActionSucceeded = false, which means our previous step failed
  • Set Error Message is Set Task Sequence Variable OSDTextErrorMessage = "All laptops require to have TPM chip. Please make sure TPM is enabled in BIOS and try again. The imaging process will end now. "
  • Error Out is a Run Command with "cmd.exe /C EXIT 7010" where 7010 is your error code. Can be anything. very important - "Continue On Error" not checked.

 

So, what happens, is that for the laptops we try to enable Bitlocker. If it fails, we execute the group where some custom variable gets set and error out with some custom error code.

So, now we need to catch this error and show the message. The best place for that is "Gather Logs and StateStore on Failure" all the way down.

Let's take a look:

Everything is out of the box until * Show OSDTextErrorMessage group, that should go right after "Copy Logs". If the variable OSDTextErrorMessage set earlier, we need to show the error message. Condition: Variable "OSDTextErrorMessage" exists.

* Dynamically Generate Error Message VB Script is just a group with no conditions, pure for grouping.

Create Error Message Script Line 1 - 4 are Run Command Line steps that create a VBS file in TEMP directory:

Line 1: CMD.EXE /C ECHO Set oTSProgressUI = CreateObject("Microsoft.SMS.TSProgressUI") > "%TEMP%\error.vbs"

Line 2: CMD.EXE /C ECHO oTSProgressUI.CloseProgressDialog >> "%TEMP%\error.vbs"

Line 3: CMD.EXE /C ECHO Set oTSProgressUI = Nothing >> "%TEMP%\error.vbs"

Line 4: CMD.EXE /C ECHO msgbox "%OSDTextErrorMessage%", 0, "Error" >> "%TEMP%\error.vbs"

So, it dynamically creates a script, then it executes it: "Show Error Message" is a Run Command Line step with cscript.exe "%TEMP%\error.vbs" command line

 

Enjoy!