Skip to content

Instantly share code, notes, and snippets.

@AdamGrossTX
Last active May 19, 2022 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamGrossTX/5d58e1d7e7438aef00314e16ef5b34e0 to your computer and use it in GitHub Desktop.
Save AdamGrossTX/5d58e1d7e7438aef00314e16ef5b34e0 to your computer and use it in GitHub Desktop.
######FOR REFERENCE ONLY. NOT COMPLETE CODE#################
#Creted for https://www.asquaredozen.com
#Twitter/GitHub: @AdamGrossTX
##Create a TSEnv Object. This gives us access to the TS variables and other environment components.
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment -ErrorAction Stop;
##Create a ProgressUI object. This object can be used to show various dialogs. We will use it for the Error Dialog.
$TSProgressUI = New-Object -ComObject Microsoft.SMS.TSProgressUI -ErrorAction Stop;
##Show the custom error dialog using the correct arguments. The \ before each " is an escape character required when running from a cmd prompt, which is what the TS will do.
#CommandLine for SCCM Clients with 1810
$TSProgressUI.ShowErrorDialog($TSEnv.Value(\"_SMSTSOrgName\"),$TSEnv.Value(\"_SMSTSPackageName\"),\"Windows Installation Error.\",\"An error occurred while installing Windows. Please contact the IT Help Desk and provide the following information:`r`nFailed Step Name: $($TSEnv.Value(\"FailedStepName\"))`r`nFailed Step Error Code: $($TSEnv.Value(\"FailedStepReturnCode\"))\",$TSEnv.Value(\"FailedStepReturnCode\"),$Tsenv.Value(\"SMSTSErrorDialogTimeout\"),0,$TSEnv.Value(\"FailedStepName\"));
#CommandLine for SCCM Clients with 1901 or Newer
$TSProgressUI.ShowErrorDialog($TSEnv.Value(\"_SMSTSOrgName\"),$TSEnv.Value(\"_SMSTSPackageName\"),\"Windows Installation Error.\",\"An error occurred while installing Windows. Please contact the IT Help Desk and provide the following information:`r`nFailed Step Name: $($TSEnv.Value(\"FailedStepName\"))`r`nFailed Step Error Code: $($TSEnv.Value(\"FailedStepReturnCode\"))\",$TSEnv.Value(\"FailedStepReturnCode\"),$Tsenv.Value(\"SMSTSErrorDialogTimeout\"),0,$TSEnv.Value(\"FailedStepName\"));
#Exit with failed step error code.
Exit $TSEnv.Value(\"FailedStepReturnCode\")"
#################################################"""
##Here's the Error Dialog broken out for each argument without the \ escape characters.
$TSProgressUI.ShowErrorDialog()
##1 - Organization Name
$TSEnv.Value("_SMSTSOrgName")
##2 - Package or TS Name
$TSEnv.Value("_SMSTSPackageName")
##3 - Custom error title
"Windows Installation Error."
##4 - Custom error details the `r and `n compbined will add line breaks to the message.
"An error occurred while installing Windows. Please contact the IT Help Desk and provide the following information:
`r`n Failed Step Name: $($TSEnv.Value("FailedStepName"))
`r`n Failed Step Error Code: $($TSEnv.Value("FailedStepReturnCode"))"
##5 - Exit Code. We are using the exit code of the failed step.
$TSEnv.Value("FailedStepReturnCode")
##6 - The timeout for the window. Setting this to the SMSTSErrorDialogTimeout lets us change the variable based on TS steps.
$Tsenv.Value("SMSTSErrorDialogTimeout")
##7 - Reboot - 0 = No Reboot, 1 = Reboot after timeout completes.
0
##8 - Task Sequence Step Name (Only for 1901 and newer clients)
$TSEnv.Value("FailedStepName")
##The final step exits the run cmdline step using the exit code of the failed step.
Exit $TSEnv.Value("FailedStepReturnCode")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment