Capture command line output with MDT Toolkit

At a client, we needed the ability to run a command on the end user’s computer and then redirect the output to the BDD/SMSTS log.  In this particular case, the issue was because the USMT Scanstate tool would choke on any files with Alternate Data Streams.  If you’re curious, ADS is a method of storing two or more ‘streams’ of data on the disk pertaining to a file.  This is not found very often, and typically only during issues like this one.  In our case, files that had been downloaded from the internet with IE and never executed would be in a state in which the file was blocked, and to unblock it one would have to right-click the file and then choose unblock.

We used this tool created by Mark Russinovich of System Internals to automate the unblocking of files, to allow the process to complete.  You can use the same script to redirect any of your own tools to the logs. If you’re just interested in creating your own log entries, you can place the following lines into your own scripts.

oLogging.CreateEntry "Remove-DataStreams: Preparing to remove ADS Information", LogTypeInfo

Hope this helps!

<job id="Remove-DataStreams">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
'// Purpose: Used to Remove Alternate Data Streams/Zone Identifiers
'// Usage: cscript Remove-DataStreams.wsf [/debug:true]
'// Version: 1.0 - 20 Nov 2012 - Stephen Owen
'// This script is provided "AS IS" with no warranties, confers no rights and
'// is not supported by the authors or Deployment Artist.
'// It should be noted that this process was needed in versions of USMT before 5.0,
'// as ScanState would fail if it encountered any files with Alternate Data Streams
'// Feel free to use this as a template if you'd like to run a command line or code
'// during a Task Sequence and want to redirect the output of the command to the BDD/SMSTS logs
'// Instructions: Copy this script and Streams.exe into your Deployment Share tools or scripts folder.  Execute
'// the script by adding a 'Run Command Line' step in MDT or SCCM.
'// Global constant and variable declarations

Option Explicit
Dim iRetVal
Dim iRC
Dim sCmd
'// End declarations
'// Main routine
On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0
'// Function: ZTIProcess()
'// Input: None
'// Return: Success - 0
'// Failure - non-zero
'// Purpose: Perform main ZTI processing
Function ZTIProcess()
oLogging.CreateEntry "Remove-DataStreams: Preparing to remove ADS Information", LogTypeInfo
' Disable Zone Checks
oLogging.CreateEntry "Remove-DataStreams: Beginning new removal method w/logging", LogTypeInfo
sCmd = "/accepteula -d -s ""C:\Documents and Settings"" "
iRC = oUtility.FindExeAndRunWithLogging( "streams.exe", sCmd )
If iRc <> 0 then
oLogging.CreateEntry "Remove-DataStreams: Error occured while running new method"
iRetVal = iRc
' Else
oLogging.CreateEntry "Remove-DataStreams: Successfully ran using new method"
' End if
'oLogging.CreateEntry "Remove-DataStreams: Beginning old method"
'Removal of ADS values begins here
'iRetVal = oUtility.RunWithHeartbeat("streams.exe /accepteula -d -s ""C:\Documents and Settings"" ")
' oLogging.CreateEntry "Remove-DataStreams: Completed Removal of ADS in C:\Documents and Settings"
'iRetVal = oUtility.RunWithHeartbeat("streams.exe /accepteula -d -s C:\")
' oLogging.CreateEntry "Remove-DataStreams: Completed Removal of ADS in C:\"
'if (iRetVal = 0) or (iRetVal = 3010) then
' ZTIProcess = Success
' ZTIProcess = Failure
' oLogging.CreateEntry "Remove-DataStreams: Error processing script Check the log."
'End If
' Enable Zone Checks
oLogging.CreateEntry "Remove-DataStreams: Return code from command = " & iRetVal, LogTypeInfo
oLogging.CreateEntry "Remove-DataStreams: Finished Removal", LogTypeInfo
End Function

Have a code issue? Share your code by going to and pasting your code there, then post the link here!

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.