Friday, January 20, 2012

SCCM 2012 – How to catch errors in Task Sequence


Issue Description:
A key requirement with a task sequence is to intelligently capture logs in case of a failure or a success. Some of the key issues faced while working with task sequences are:
  1. Log files in a task sequence hop from one folder to another depending on the OS installation and the SCCM Client Installation status.
Path of the log fileOS StatusSCCM Client Status
<largest fixed partition>\SMSTSLOG Windows PENot Applicable
%temp%\SMSTSLOGS full operating system No
C:\windows\ccm\Logs full operating system Yes

  1. This issue of hopping log files accentuates when the Task Sequence fails and it is difficult to locate the exact location of the log files.

     
  2. It also becomes challenging to look for smsts logs when mass deployments are done. It is important to know how to manage logs for successes and failures, therefore the requirement is to copy the smsts.log to a central share and easily differentiate whether the deployment was a success or a failure

     
  3. In addition, when a particular task of the sequence fails, there is an error prompt that stays for 15 minutes or so and the machine reboots thereafter. In case the administrator is not in front of the machine where the TS failed, he or she would not know upfront that there was a failure until he or she checks the log files. Therefore one requirement is to halt the task sequence where it fails
Solution Description:
Based on the above issues and requirements, the key tasks we need to accomplish are:
  1. If the task sequence (TS) is a success, then
    1. The logs should get copied to a central share
    2. Into a folder called SUCCESS
    3. And the TS should complete gracefully
  2. If the TS is a failure, then
    1. the logs should get copied to a central share
    2. into a folder called FAILURE
    3. Also the TS should halt immediately so that the admin can see that there was a failure
We will accomplish this requirement by using in-built variable in the task sequence - _SMSTSLastActionSucceeded. This variable captures the state of the last action and returns TRUE when the action was successful and FALSE when there was an error.



#DescriptionScreenshot
1
  • Put the entire logic of the Task Sequence including OS install, application install, driver install, etc under a main group called MAIN TS
  • At the same level of the Main TS, put another action called Try Catch
  • Create 2 sub groups under Try Catch called:
    • Success
    • Failure
  • The idea is to capture any errors that happen in the Main TS into that try catch action
2
  • Set "Main TS" group to Continue on error
3
  • Add a condition to the "Success" group:
Evaluate whether the TASK SEQUENCE VARIABLE: _SMSTSLastActionSucceeded equals TRUE
  • Here the variable _SMSTSLastActionSucceeded captures the status of the last task executed
  • If there is a failure in the MainTS, the _SMSTSLastActionSucceeded will be set to false, else true
  • The TS will enter Success group only if there are no errors in the previous tasks



4
  • Similarly, add another condition to the "Failure" group:
Evaluate whether the TASK SEQUENCE VARIABLE: _SMSTSLastActionSucceeded equals FALSE
  • The TS will enter Failure group only if there are errors in the previous tasks



5Add the following logic under the Failure Group:
This is the share where all the logs will get copied
6
  • Delete any folder associated with a computer name in the Failure Folder -> \\<servername>\LogFileShare\Failure\<computername>
  • Add a Run Command Line tasks and put the following command in the command line:
  • cmd.exe /c rd L:\Failure\%_smstsmachinename%% /s /Q
  • Here %_smstsmachinename%% command refers to the computer name of the target computer
This task is necessary to ensure all earlier logs corresponding to the machine are deleted
7
  • Create a new folder in the Failure folder for the computer name -> \\<servername>\LogFileShare\Failure\<computername>
  • Add a Run Command Line tasks and put the following command in the command line:
  • cmd.exe /c md L:\Failure\%_smstsmachinename%%
8
  • Copy the log files from the smstslog file path to \\<servername>\LogFileShare\Failure\<computername>
  • Add a Run Command Line tasks and put the following command in the command line:
  • cmd.exe /c copy %_smstslogpath%\*.* L:\failure\%_smstsmachinename%
9
  • Halt the Task Sequence by invoking a simple wscript.echo command
  • Invoke a simple vbscript that prompts the path of the folder where the logs are kept:
  • Script.echo "There is an error in the task sequence implementation. The log files are stored at \\<servername>\LogFileShare\"
10
  • Add similar tasks for group "Success"
11
  • Create a folder on the server for storing the logs and share it with Everyone Full Control
  • Create 2 additional folders called Failure and Success
12
  • The Failure and Success folders will get populated with appropriate computer names









38 comments:

  1. Hello Sandeep,

    This is a terrific article, well explained and easy to follow.

    Whilst I haven't implemented your steps in my environment, I do plan to do something like this so that I am aware of Task Sequence failures.

    I have been investigating whether it is possible to trigger an email to be sent when a Task Sequence completes, but your suggestion of writing to files is just as useful.

    Regards,
    Daniel
    Melbourne, Australia

    ReplyDelete
    Replies
    1. I am glad that you found this article useful. Daniel, regarding your requirement to send an email after the TS, you can create a vbscript and call it at the end of the Task Sequence:

      Set objEmail = CreateObject("CDO.Message")
      objEmail.From = "me@mydomain.com"
      objEmail.To = "you@yourdomain.com"
      objEmail.Subject = "Server is down!"
      objEmail.Textbody = "Server100 is no longer accessible over the network."
      objEmail.Send

      reference: http://www.petri.co.il/send_mail_from_script.htm

      Delete
    2. It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download Now

      >>>>> Download Full

      It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download LINK

      >>>>> Download Now

      It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download Full

      >>>>> Download LINK zx

      Delete
  2. Hello,

    I have this working in my environment, and it is awesome. I used %OSDComputerName% instead though, to get the more friendly name of the machine, instead of MININT-XXXXXX

    ReplyDelete
    Replies
    1. Thank you. it is very heartening to see that you found the article useful :)

      Delete
    2. I know this is a pretty old comment but I was just wondering how you got %OSDComputerName% to work. I'm not having any luck, my folder keeps getting created as literally "%OSDComputerName%" instead of the true computer name. I do use this variable earlier in my TS to set the computer name so I just assumed I could use it again in this instance.

      Delete
    3. I think that's because you need MDT integrated in SCCM to use this variable. But I'm not 100% sure.

      Delete
  3. Hi Sandeep,
    Looks like your famliar with SCCM.Basically Iam begineer to SCCM. Can you help me in getting some notes/stuffs for SCCM which includes of Planning, Deploying and Managing Microsoft System Center Configuration Manager 2007

    Regards,
    Santosh

    ReplyDelete
  4. Hi Sandeep, great article! Thanks for the info.
    Would it be possible for you to share the AddErrorPrompt.vbs file that you used to halt the TS and display the error message?

    Thanks again!
    Phil

    ReplyDelete
  5. Excellent article!! Your explanations are awesome.
    Thanks
    Tom

    ReplyDelete
  6. The AddErrorPrompt.vbs is just at txt string like this:
    WScript.Echo "There is an error in the task sequence implementation." & VbCrLf & VbCrLf & "The log files are located at \\Your server\TSLogFile\"

    ReplyDelete
  7. Hey Sandeep,
    I actually DID credit my source for that info in my blog post (which I wrote based on the steps I did to implement a similar solution; I didn't "copy paste" as you said). If you look, you can see that I credited Steve Rachui and link to his post from July of 2008 (http://blogs.msdn.com/b/steverac/archive/2008/07/15/capturing-logs-during-failed-task-sequence-execution.aspx) in the opening paragraph. His post is from a year and a half before your article, and is the one I found when I was was trying to set this up.

    Thanks anyway!
    -Mark

    (I tried to send this via email but the email address you used to leave the comment on my page doesn't work.)

    ReplyDelete
  8. This is exactly what I was looking for thank you so much.

    ReplyDelete
  9. This is a great article.
    My apologies for I'm a beginner in SCCM 2012. I also have a task sequence for a Terminal Server which involves many steps (installing update/software/reboots).
    Would I need to create this logic after/during each step or just once at the bottom as final step of the TS..?

    ReplyDelete
  10. Bonjour,

    Merci pour cet article.

    Bonne continuation.

    ReplyDelete
  11. Hi Thank you for a very intuitive article. After following the steps above, my still doesn't work. I also do not understand the part where you ticked the package tickbox. Where was that package created? My vb script also does not prompt me at all. I have followed the steps diligently but, the only part I missed out is the packed bit. What am I doing wrong?

    ReplyDelete
  12. hej there,
    thank you for this great howto. i have problems deleting existing folders with cmd.exe /c rd L:\Failure\%_smstsmachinename%% /s /Q. the logfile says: no such folder or file. is the variable working?

    kind regards
    tommy

    ReplyDelete
  13. I keep getting a disconnected network drive on my clients when following this guide..

    Any ideas?

    ReplyDelete
  14. @Martin Thomson, you need to run a command line after the logs have been copied that basically does the following:

    cmd.exe /c net use L: /delete

    ReplyDelete
  15. Check out my post here http://d4rkcell.com/archives/1547 which uses this structure but builds upon the command line usage. It uses a VBS script to copy the logs and so far it works well.

    ReplyDelete
  16. SCCM JOBS ADDA

    http://dhuvurunaresh.blogspot.com/

    ReplyDelete
  17. http://dhuvurunaresh.blogspot.com/

    ReplyDelete
  18. I did as you instructed here but it wasn't working so I tested and found it would be easier to have it write to the destination using a UNC path. I tested all the commands by running them in an admin command prompt and it created and deleted folders yet when the TS is over no new files are created in Success or Failure. I have MDT so I'm not sure what's going wrong?

    ReplyDelete
  19. Hi Sandeep,
    TS fails at the stage when system is not getting IP. At that time mapping a network drive is not possible to copy the logs.
    do you have any solution for that ??

    ReplyDelete
  20. It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download Now

    >>>>> Download Full

    It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download LINK

    >>>>> Download Now

    It Evangelist: Sccm 2012 – How To Catch Errors In Task Sequence >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete