Get Task Sequence Failure Notification Emails and Store the SMSTS.log file for Review
Posted on September 20th, 2018
It can be frustrating when a task sequence you took time to build and test up and 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 fails.
Either way you have to take time and grab the task sequence smsts.log, so you are able to effectively troubleshoot the issue with the task sequence.
What if I told you, you could save time by receiving a notification when a task sequence fails and go to a specified location to retrieve the smsts.log file for quick troubleshooting review?
Well, you are able to do this and here is how.
Setting up the Task Sequence to Copy the Log Files
First step is making sure that your task sequence has a main group and then 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.
Ok. 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.
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.
Now comes 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 need 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.
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, you may want to make a special account just for this process and then add the user account permission of full or modify just to the folder location of where you would like to store the log files not to the entire file share directory.
Next, 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
cmd.exe /c IF EXIST t:\%OSDComputerName% rd /s /q t:\%OSDComputerName%
Next, 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 machine
cmd.exe /c md t:\%OSDComputerName%
Now, 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
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
cmd /c exit 1
Getting the Email Notification
This is were that last Run Command Line Intentional Error comes into play. 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.
Expand the Overview node.
Expand the Site Configuration node.
In the top ribbon click on Status Filter Rules in the Settings section.
In the Status Filter Rules window, click on Create...
Fill in the following information.
Message ID: 11170
Property: Package ID
On 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
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 = $SendersEmailAddressSend-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.