MDT Scripting: Managing Log Files

During deployments, MDT has a powerful logging process. All the logs generated are in a format similar to SCCM so you can use the Trace32 tool to view the log files in a GUI. Your custom scripts will generate individual log files during execution. In addition, you can write your own custom messages that will appear time stamped as lines within these log files and also in the bdd.log file.

I’m going to demonstrate how to write a few simple information messages to a log file using the ZTIUtility.vbs ologging class with the CreateEntry method. It’s usage is as follows:

oLogging.CreateEntry(sLogMsg, iType)

As usual in your MDT Script Template, add these lines:

oLogging.CreateEntry "Scriptimus Ex Machina - Logging: Begining logging process", LogTypeInfo
wscript.echo "Hello world"
oLogging.CreateEntry "Scriptimus - This ia an Information Log Entry", LogTypeInfo
oLogging.CreateEntry "Scriptimus - This ia a Warning Log Entry", LogTypeWarning
oLogging.CreateEntry "Scriptimus - This ia an Error Log Entry", LogTypeError
oLogging.CreateEntry "Scriptimus Ex Machina - Logging: End logging process", LogTypeInfo

Run the script and examine the output. As you can see below, the log entrys include an echo to the command line.

These lines each create a log entry using the LogTypeInfo, LogTypeWarning and LogTypeError parameters. There are a number of parameters available for use.

LogTypeInfo        = 1   ‘ Informational Message
LogTypeWarning     = 2   ‘ Warning Message
LogTypeError       = 3   ‘ Error Message
LogTypeVerbose     = 4   ‘ Verbose Messages only logged when Debug has been set.
LogTypeDeprecated  = 5   ‘ Informational Message that is elevated to Error when Debug is set.

In the MININT\SMSOSD\OSDLOGS\ folder you will find a log file with the same name as your script. You can open it with Notepad or Trace32.

In the log file collected below you will see that Information logs have a type of 1, Warnings have a type of 2 and Errors have a type of 3.

<![LOG[Microsoft Deployment Toolkit version: 6.0.1763.0]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="1" thread="" file="SEM-Logs">
<![LOG[Scriptimus Ex Machina - Logging: Begining logging process]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="1" thread="" file="SEM-Logs">
<![LOG[Scriptimus - This ia an Information Log Entry]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="1" thread="" file="SEM-Logs">
<![LOG[Scriptimus - This ia a Warning Log Entry]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="2" thread="" file="SEM-Logs">
<![LOG[Scriptimus - This ia an Error Log Entry]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="3" thread="" file="SEM-Logs">
<![LOG[Scriptimus Ex Machina - Logging: End logging process]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="1" thread="" file="SEM-Logs">
<![LOG[SEM-Logs processing completed successfully.]LOG]!><time="01:00:36.000+000" date="07-21-2011" component="SEM-Logs" context="" type="1" thread="" file="SEM-Logs">

In Trace32 you will see that the warning messages appear in yellow and the error messages appear in red.

Other advanced logging methods are:

oLogging.ReportFailure (sMessage,iError)
Used to perform a structured exit if an unrecoverable error is detected.

oLogging.CreateEvent(iEventID, iType, sMessage, arrParms)
Write a message to the log file, and post the event to a defined server.

About these ads

About Andrew Barnes

A Scipting and Deployment Specialist.
This entry was posted in MDT 2010, Scripting and tagged , , . Bookmark the permalink.

2 Responses to MDT Scripting: Managing Log Files

  1. John Dunn says:

    Where is the time stamp generated from for the BDD.log, is it the target machine or is the time stamp acquired from the network, server, or what?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s