Working with OSD for a large organization can be very frustrating at times for several reasons. Especially when staff you are providing support for are located at different locations.

When a task sequence fails you have to rely on others to provide the log files and any other helpful information that may aid in resolving a task sequence failure.  

We review the process of creating a custom task sequence failure notice UI that shows a form to the user stating that the task sequence failed and to fill out the form to receive assistance with the failure.

Looking for a different method for receiving task sequence failure notifications? Check out my previous article Get Task Sequence Failure Notification Emails and Store the SMSTS.log File for Review

Requirements

  • ServiceUI.exe file from MDT, this can be downloaded from the Github repository here.
  • Mail-enabled security group (optional, but recommended)
  • Your organizations SMTP server
  • System Center Configuration Manager version 1710 or later The Script The full script can be obtained from Github.

Explanation of Code

I will try and narrow down the explanation of the script to just the areas that may not be as self-explanatory. The PowerShell script consists of one major function. That function is the Start-Form function.

The Start-Form function contains the form elements, form validation, and Send-MailMessage function.  The first thing the script does is stops and closes the default TSProgressUI that is normally seen when a task sequence fails. The below snippet is what initiates this action.

$TSProgressUI = New-Object -ComObject Microsoft.SMS.TSProgressUI
$TSProgressUI.CloseProgressDialog()
$TSProgressUI = $null

The next important area is where the OnChange is handled. These are for real-time form validation as the user navigates the textbox fields. Each TextChanged event is handled by the ValidateTextboxes function.

# The ValidateTextboxes are tied to the event.
  $TxtName.Add_TextChanged({ ValidateTextboxes })
  $TxtTsName.Add_TextChanged({ ValidateTextboxes })
  $TxtEmail.Add_TextChanged({ ValidateTextboxes })

The ValidateTextboxes function only checks to ensure that the required fields contain input. If the fields are null or empty then the validation fails. There is one exception and that is the email address field this requires input, but also requires that the email be formatted correctly, i.e, '*@*.*'. To accomplish the email format validation the script uses a regular expression.

# validate that the email provided is in the correct format.
    function Validate-IsEmail {
        param([string]$Email)
        return $Email -match "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|"+`
                        "[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))"+`
                        "(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*"+`
                        "[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"
    }

The Send-Mail function sends the email message to the intended recipient(s). You can either choose to add an email address here or you can use a mail-enabled Active Directory security group. You will also need to add your organizations SMTPServer address.

$SMTPServer = "SMTP_SERVER_ADDRESS" # ADD YOUR SMTPSERVER ADDRESS
$EmailAddress = "SECURITY_GROUP_EMAILADDRESS" # SECURITY GROUP EMAIL ADDRES

Feel free to place the file paths in the Send-Onclick function into variables. I may choose to complete this at a later time and update the GitHub repository.

The Send-Onclick function checks to see if the path exists if the path to the SMSTS.log file exists then it copies the log files to a new directory. The files need to be copied to a new directory because the SMSTS.log files are currently in-use. The files are then added to an array of type string and added to the '-Attachments' parameter associated with the Send-Mail function.  

Create the Program

Start the Package and Program Wizard in SCCM, and enter the following settings for the program.  

Package

  • Name : Enter a name for the package
  • Place a check mark for This package contains source files
  • Source folder, navigate to the folder location of the .PS1 file.
  • Click Next

Choose the program type that you want to create

  • Select the Do not create a program radial and click, Next

Confirm the Settings

  • Click Next

The Create Package and Program Wizard completed successfully

  • Click  Close

After successfully creating the package distribute the package to your distribution points.

Setup the Task Sequence

The task sequence should be set up similar to what is pictured below. The only required parts for this is the Try and Catch groups.  

Apply the following settings to the Try group:

Apply the following settings to the Catch group:

  • Variable _SMSTSLastActionSucceeded
  • Condition equals
  • Value false

The final step is to add the program that was created in the 'Create the Program' step to the task sequence. After adding the PowerShell program to the task sequence Catch group, the task sequence should now look similar to the below image.

In the command line field enter the following command:

ServiceUI.exe -process:TSProgressUI.exe %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File Show-TSFailureNotice.ps1

Place a check mark next to Package and browse to the package that was created in the 'Create a Program' step.

The task sequence now has a custom failure notice that will send the log files to the email address that was specified in the PowerShell script.

You can download the script and the ServiceUI.exe file from github here.