Querying MDT/ConfigMgr Logs in MDT Scripts

The Lite Touch Deployment Process end in a Summary Wizard pane that displays any warning or errors that were logged in the MDT master log (BDD.log).

clip_image001

This is a great feature but customers have pointed out that this summary is not preserved after the Summary Wizard is closed.  If you accidentally Finish before reading everything, you now have to open the log and start trawling through it.

So what I was initially going to do to preserve this information was to change Summary_scripts.vbs (the part of the Summary Wizard code that does the work) to write the same information to a text file.  However, as I pondered this I realized that there was no general purpose function for querying logs in SMS format.  So instead of just changing Summary_scripts.vbs I decided to create such query functionality and then use that.

The log format used by MDT and the ConfigMgr client/task sequencer has been around since Microsoft Systems Management Server.  It is an XML-like format with entries that look like this:

<![LOG[Successfully finalized logs to E:\SMSTSLog]LOG]!><time="06:20:42.077+240" date="05-23-2009" component="TSBootShell" context="" type="1" thread="908" file="tslogging.cpp:1635">

The actual message text is found inside the <![LOG[…]LOG]!> tags and the other information about the entry (time, date, component, type, etc.) is found in XML-like attribute entries within the second <…> braces.  The message text may be a single line or multiple lines of text.  The closing ]LOG]!> and the attributes block will always be on the last line of the entry.

Since Summary_scripts.vbs was already doing part of the parsing of this log format, I used that code as a starting point.  The result is a new VBScript class script, MDTQuerySMSLog.vbs, to use with MDT scripts.  This SmsLog class in the script has three public methods.  The most useful is ConvertToXmlObject.  This method converts the contents of an SMS-format log file into an XML object representation.  This allows you to query the contents using standard XPath queries.  For example, a log consisting of the single entry below:

<![LOG[Property LogPath is now = C:\MININT\SMSOSD\OSDLOGS]LOG]!><time="10:24:21.000+000" date="06-04-2010" component="ZTIGather" context="" type="1" thread="" file="ZTIGather">

will be converted into the following XML data:

<?xml version="1.0" encoding="utf-8"?>
<LogEntries>
<Log id="1" line="1" time="10:24:21.000+000" date="06-04-2010" component="ZTIGather" context="" type="1" thread="" file="ZTIGather">Property LogPath is now = C:\MININT\SMSOSD\OSDLOGS</Log>
</LogEntries>

Every log entry is turned into an XML Log node where the message text is the node text and the entry attributes are the node attributes.  There are also two additional attributes added: id which is the log entry number from the original log file and line which is the line number on which the entry started in the original log file.

Another method, ConvertToArray, converts the log contents to a two dimensional array where each row in the array contains the same attributes and message text that the XML version contains.  The last method is LogDateTimeToVBDate which takes the SMS log date and time attributes and returns a VBScript Date value.

To illustrate how to use this class I’ve included a sample script, MDTErrorWarningSummary.wsf, that uses ConvertToXmlObject, LogDateTimeToVBDate and XPath queries to create a more detailed version of the error and warning entries (type="3" and type="2" repectively) summary that the Summary Wizard creates. It creates this summary in ErrorWarningSummary.log in the MDT logs folder.  The contents looks like this:

Total number of entries logged in C:\MININT\SMSOSD\OSDLOGS\BDD.log: 48
Number of errors logged in C:\MININT\SMSOSD\OSDLOGS\BDD.log: 1
Number of warnings logged in C:\MININT\SMSOSD\OSDLOGS\BDD.log: 1

Warning
=======
Log Entry: 3
Log Entry stating line number: 3
Date/Time: 8/2/2011 2:16:18 PM
Component: ZTIMyComponent
Message: This is a warning message.

Error
=====
Log Entry: 9
Log Entry stating line number: 9
Date/Time: 8/2/2011 2:16:18 PM
Component: ZTIMyComponent
Message: This is an error message.

You can launch this script at the end of the task sequence or add an oShell.Run call to Summary_scripts.vbs to launch the script.

If you use this class with your own custom script, be aware that ConvertToXmlObject creates a point in time capture of the log contents.  So if you wanted to use this for something like repeatedly checking a log for a particular message as the log changes, you would need to call ConvertToXmlObject in each iteration of you loop to recapture the full contents.

 

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .

This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.

MDTQuerySMSLog.zip