This idea grew out of the need to troubleshoot certain task sequence errors. Usually when your task sequence throws an error, the code will be displayed for an X amount of time after which the machine reboots. Retrieving the SMSTS.LOG file is somewhat cumbersome, as the exact location of the file varies depending on which phase of the OSD the machine is in:
|OSD PHASE||SMSTS.LOG LOCATION|
|WinPE, Before HD Format||x:\windows\temp\smstslog\smsts.log|
|WinPE, After HD Format||x:\smstslog\smsts.log|
|Windows, No SCCM Client Installed||c:\_SMSTaskSequence\Logs\Smstslog\smsts.log|
|Windows x86, SCCM Client Installed||c:\windows\system32\ccm\logs\Smstslog\smsts.log|
|Windows x64, SCCM Client Installed||c:\windows\sysWOW64\ccm\logs\Smstslog\smsts.log|
|Task Sequence Completed x86||c:\windows\system32\ccm\logs\smsts.log|
|Task Sequence Completed x64||c:\windows\sysWOW64\ccm\logs\smsts.log|
An easier way to gather these logs is to take advantage of a Task Sequence Variable within the OSD deployment. Whenever the task sequence finishes either successfully or not, the TS variable “_SMSTSLastActionSucceeded” returns a true or false value. We can then leverage this variable to create a step in the task sequence to run only if the return value is false and then further run some steps to map a network drive and copy the logs over. I was lucky to find an old post by Steve Rachui, a Microsoft Premier Field Engineer which helped saved me time brainstorming a solution. However, my implementation makes use of the %OSDComputerName% variable and displays a custom error message in order to prevent WinPE from rebooting after clearing the countdown.
Below are the steps I took:
- Created a network share and allowed “Everyone” full access permission. You can restrict this share to a specified AD account if you wish but you will then need to specify the account in the steps below. I named my network share “TSLogCapture”.
- In the root of your task sequence, create a new group named “Task Sequence” and move all the steps as a subfolder to this new group. In the Options tab, make sure the “Continue on error” box is checked. The idea is to have all the steps grouped and if there is an error, pass control to the next group which will copy the logs to a share.
- Also in the root of your task sequence, create another group named “Log Capture”. In the Options tab add a condition to run when the task sequence variable “_SMSTSLastActionSucceeded” equals “False”.
- We will need to add the above displayed steps to the “Log Capture” folder. To add the first step, go to Add, General, Connect to Network Folder.
In the Properties tab, you will need to specify a Path, Drive Letter and Account to connect and map the network share. If you restricted the network share to a specific AD account, input that account here. Also, please note I chose the “Z:” drive letter, therefore, all my command line entries reflect this drive letter. If you choose a different drive letter, please update any subsequent command lines with this new drive letter.
- Now we will need to add “Run Command Line” steps to the “Log Capture” folder. To add this step, go to Add, General, Run Command Line. This step will remove any pre-existing folders for that machine name you are currently using from the network share. Its purpose is to prevent duplicate log files.
cmd.exe /c rd /s /q z:\%OSDComputerName%
- Add another “Run Command Line” step. This step will create a folder named after the computer name in the TS variable %OSDComputerName% (a friendly name of your choosing). You can also use %_SMSTSMachineName% which will name the folder after the random “MiniNT-12345” name if the error occurs in WinPE or after the actual AD computer name if the error happens in Windows.
cmd.exe /c md z:\%OSDComputerName%
- Add another “Run Command Line” step. This step will copy the log files from the path contained within the %_SMSTSLogPath% variable to machine named folder in the network share.
cmd.exe /c copy %_SMSTSLogPath%\*.* z:\%OSDComputerName%
This last step is entirely optional. I use it to display a custom error message using VBScript in order to prevent the error countdown from starting and rebooting the machine. To add this step, you will need to create a Package out of one file, ErrorPrompt.vbs. To create this file, open Notepad.exe and copy/ paste the following and update the path to your network share:
WScript.Echo "There was an error in the task sequence." & VbCrLf & VbCrLf & "Please review the log files stored at: [Your Network Share Path Here]"
Next, save the VBScript file in a folder in your SCCM package repository and create a package using the SCCM Administration Console:
Click on “Next” all the way until the package is created. Once complete, you will need to distribute it to your distribution points or groups.
Once again, click “Next” until you finish distributing the package. You will need to watch the “Content Status” pane in the package information section to verify that the package was distributed successfully.
Now that you have created your package and have it distributed to your distribution points. You may proceed creating that last “Run Command Line” step in your task sequence. In the Properties tab, insert the following command line and don’t forget to specify the package we created:
cmd.exe /c wscript.exe errorprompt.vbs
Phew! We are finally done! Give yourself a good pat on the back because from now on, whenever your task sequence encounters an error, you will see the following: