Get Task Sequence Failure Notification Emails and Store the SMSTS.log file for Review

Get Task Sequence Failure Notification Emails and Store the SMSTS.log file for Review

It can be frustrating when a task sequence you took time to build and test fails for some reason. It also can be frustrating to receive a help ticket stating that the task sequence failed and the ticket only contains a picture of the TSPRogressUI with a generic error code, or the ticket just plainly says the task sequence failed.

Either way, you have to take time and grab the task sequence smsts.log, so you are able to effectively troubleshoot the issue. What if I told you, you could save time by receiving a notification when a task sequence fails, and go to a location to retrieve the smsts.log file for quick troubleshooting review?

You can setup the Task Sequence to Copy the Log Files to a specified folder. The first step is making sure that your task sequence has a main group and a catch error group. I have created a simple task sequence for display purposes, but yours should look similar.

Now that we have the task sequence created we want to move the Setup Operating System group under the Install Operating System group.

We need to make one last modification to the main part of the task sequence. Click on the Install Operating System group name.

Click on the Options tab, and place a check in the box next to Continue on error. Enabling 'Continue on error' is what is driving the try/catch.

Now, any process that will fail underneath the Install Operating System group will continue on error.

Next, we need to create another group. Let's call it Catch TS Error. Your task sequence should look similar to the below image.

Next, adding the logic to store the smsts.log file for you to reference after you receive the email notification that the task sequence failed.

Ok, The Catch TS Error group needs to know its purpose. How do we do this? Easy, Click options > Add Condition > Task Sequence Variable .

The task sequence needs to connect to a network location.

Add the step Connect to Network Folder step. It is located under Add > General. Insert the path to the file share you would like the smsts.log file to be stored in.

Choose a drive letter to use. Finally, enter the username and password of the account that can access and has full or modify rights to this storage locations.

*Note, it's recommended to make a service account just for this process and then give the service account permission of full or modify to the folder location where you would like to store the log files, not to the entire file share directory.

The task sequence needs to check and erase any preexisting folders for devices with the same computer name. Click the Add > General > Run Command Line

Name: Erase any pre-existing folder for machine

Command line:

cmd.exe /c IF EXIST t:\%OSDComputerName% rd /s /q  t:\%OSDComputerName%

Let's have the task sequence create a new folder with the machine name to store the smsts.log files. Click on Add > General > Run Command Line

Name: Create log folder for current machineCommand Line:

cmd.exe /c md t:\%OSDComputerName%

The task sequence needs to copy the smsts.log files to the newly created folder. Click Add > General > Run Command Line

Name: Copy logs to folder

Command Line:

cmd.exe /c copy %_smstslogpath%\*.* t:\%OSDComputerName%

Last modification to the task sequence and the most important to get the email notifications to work. We need to tell the task sequence to fail. Click Add > General > Run Command Line

Name: Intentional Error

Command Line:

cmd /c exit 1

Getting the Email Notification

To get the email notification we want to make a Status Filter Rule that runs a PowerShell script to email some information about the failure.

Let's create the Status Filter Rule to accomplish this. Open the Configuration Manager Admin console and click on Administration > Overview > Site Configuration > Sites.

In the top ribbon click on Status Filter Rules in the Settings section.

In the Status Filter Rules window, click on Create and fill in the following information.

Name: 'Name of Status Filter Rule'
Source: Client
Message ID: 11170
Property: PackageID
Property Value: 'Insert the ID of the task sequence you would like to monitor'

Click, OK

In the Specify the actions windows place a check in Run a program.

In the Program text field enter the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file <Full_Path_To>\Send-TSFailure.ps1

Click Next, Next, Close.

Here is a copy of the Send-TSFailure.ps1

$Subject = "Task Sequence Failure Notice"
$Body =  "Task Sequence Name failed to complete successfully."
$SMTPServer = $YourServer
$EmailAddress = $SendersEmailAddress
Send-MailMessage -Subject $Subject -Body $Body -From $EmailAddress -To $EmailAddress -SmtpServer $SMTPServer​

If all is successful you should receive a failure notice via email and be able to reference the SMSTS.log file at the network location you specified.