Share This Post

SCCM Task Sequence Completion: Email Notification

Have you ever wanted some notification that a task sequence has completed? I wrote 2 simple scripts to do just that, with a little bonus added information. They are super easy to integrate into your task sequences. The first script should run as the very first step and simply asks for your email address and places it into a custom TS variable. The second script runs at the very end of the task sequence and sends a notification to the email address with some pretty cool information, PC name, make and model, how long it took to complete, and finally a sorted list of non-update related entries in add/remove programs.

Feel free to use these scripts as a baseline and modify them to pull in whatever kind of information is useful to your technicians. Here’s a sample of the email I received after a workstation I recently imaged finished.

PC CDQJZ3J1 completed the imaging process at 9/30/2010 2:34:33 PM

Model: Dell Inc. Precision WorkStation T5400

The process took 1 hours and 20 minutes to complete. Started at 9/30/2010 1:54:07 PM and ended at 9/30/2010 2:34:33 PM

Installed Applications:

Adobe Flash Player 10 ActiveX

Adobe Reader 9.3 9.3.0

Citrix XenApp Plugin for Hosted Apps

Compatibility Pack for the 2007 Office system 12.0.6514.5001

Configuration Manager Client 4.00.6487.2000

J2SE Runtime Environment 5.0 Update 11

Microsoft Forefront Client Security Antimalware Service 1.5.1937.3

Microsoft Forefront Client Security State Assessment Service 1.0.1703.0

Microsoft Operations Manager 2005 Agent 5.0.2911.0

Microsoft Silverlight 3.0.50106.0

MSXML 4.0 SP2 (KB954430) 4.20.9870.0

MSXML 4.0 SP2 Parser and SDK 4.20.9818.0

That script looks like this:


‘J. Clarke

set env = CreateObject("Microsoft.SMS.TSEnvironment")

Name = inputbox("If you would like to be notified when the imaging process is complete, please enter your email address." ,"Prompt for Email Address:",,400,0)

‘Set TS variable for the technician’s email address.

env("OSDNotifyEmailAddress") = Name

‘Set custom TS variable so we can see how long the task sequence takes.

env("ImageStartTime") = Now

I wrote this script using the CDOSys Send method. To use this script in your environment, you only need to change 2 configurations in the SendMailCDOSYS subroutine, which is at the very bottom: The FROM and the SMTP server to use for sending the email. To test this script, you can simply comment out the first 3 lines of code, and use the debug data. This way you can test before you actually put it in a task sequence.

‘ NotifyTechnician.vbs

‘ This script will notify the technician that the imaging process has completed.

‘Joe Clarke

set env = CreateObject("Microsoft.SMS.TSEnvironment")

strRecipient = env("OSDNotifyEmailAddress")

strFirstTime = env("ImageStartTime")

‘ *** sample data for debug

‘strRecipient = ""

‘strFirstTime = "4/28/2010 10:35:55 AM"

Const adVarChar = 200

Const MaxCharacters = 255

Const ForReading = 1

Const ForWriting = 2

Const ForAppending = 8


Set fso=CreateObject("Scripting.FileSystemObject")

‘Get relevant computer information

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _

wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems

strManufacturer = objItem.Manufacturer

strModel = objItem.Model

strArchitecture = objItem.SystemType

strComputerName = objItem.Name


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms", "WQL", _

wbemFlagReturnImmediately + wbemFlagForwardOnly)

‘strFirstTime = "4/26/2010 7:52:23 AM"

If strFirstTime <> "" Then

strHours = DateDiff("h",strFirstTime,Now)

strHoursX60 = strHours * 60

strMinutes = DateDiff("n",strFirstTime,Now)

strRealMinutes = strHoursX60-strMinutes

‘msgbox "The image took " & strHours & " hour(s) and " & strRealMinutes & " minute(s) to complete."

End If

strSubject = "PC " & strComputerName & " has completed the imaging process."

strBody = "PC " & strComputerName & " completed the imaging process at " & Now & Chr(13) & "Model: " & strManufacturer & " " & strModel & Chr(13) & Chr(13) & "The process took " & strHours & " hours and " & strRealMinutes & " minutes to complete. Started at " & strFirstTime & " and ended at " & Now & Chr(13) & Chr(13) & "Installed Applications: " & Chr(13)

‘Check to see if Aultman Logging folder is setup. If not, set one up.

If Not fso.FolderExists("C:\Program Files\OSD Logging") Then

fso.CreateFolder "C:\Program Files\OSD Logging"

End If

‘Set up logging for this script.

strLogFileName = "C:\Program Files\OSD Logging\Installed_Applications.txt"

If Not fso.FileExists("C:\Program Files\OSD Logging\Installed_Applications.txt") Then

Set objLogFile = fso.CreateTextFile(strLogFileName)


Set objLogFile = fso.OpenTextFile(strLogFileName, ForAppending)

End If

For Each objItem In colItems

‘WScript.Echo "DisplayName: " & objItem.DisplayName

ReDim Preserve arrNames(intSize)

arrNames(intSize) = objItem.DisplayName

intSize = intSize + 1

Bogus = "No"

If instr(objItem.DisplayName,"Security Update") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"Hotfix for") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"Update for Windows") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"Microsoft National") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"Windows Management Framework") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"Microsoft Internationalized") Then

Bogus = "Yes"

End If

If instr(objItem.DisplayName,"WIMGAPI") Then

Bogus = "Yes"

End If

If objItem.DisplayName = "RDC" Then

Bogus = "Yes"

End If

If Bogus = "No" Then

If objItem.DisplayName <> "" Then

WriteLog objItem.DisplayName & " " & objItem.Version

End If

End If



‘* Write String to Log File

Sub WriteLog(strString)

objLogFile.Writeline strString

End Sub



‘* Sort List alphabetically

Set DataList = CreateObject("ADOR.Recordset")

DataList.Fields.Append "ComputerName", adVarChar, MaxCharacters


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Program Files\OSD Logging\Installed_Applications.txt", ForReading)

Do Until objFile.AtEndOfStream

strLine = objFile.ReadLine


DataList("ComputerName") = strLine




DataList.Sort = "ComputerName"


Do Until DataList.EOF

strText = strText & DataList.Fields.Item("ComputerName") & vbCrLf



Set objFile = objFSO.OpenTextFile("C:\Program Files\OSD Logging\Installed_Applications.txt", ForWriting)

objFile.WriteLine strText



‘* Read Installed_Applications.txt into a variable

Set objTextFile = objFSO.OpenTextFile _

("C:\Program Files\OSD Logging\Installed_Applications.txt", ForReading)

Do Until objTextFile.AtEndOfStream

strComputer = objTextFile.ReadLine

strBody = strBody & Chr(13) + strComputer & Chr(13)



‘Clean up Remove.txt

If fso.FileExists("C:\Program Files\OSD Logging\Installed_Applications.txt") Then

fso.DeleteFile "C:\Program Files\OSD Logging\Installed_Applications.txt",force


If strRecipient <> "" Then

SendMailCDOSYS strRecipient, strSubject, strBody

End If


Sub SendMailCDOSYS (strRecipient,strSubject,strMessage)

‘Create the e-mail server object

Set objCDOSYSMail = CreateObject("CDO.Message")

Set objCDOSYSCon = CreateObject ("CDO.Configuration")

‘Set and update fields properties

‘Out going SMTP server

objCDOSYSCon.Fields("") = "<yourSMTPmailserver>.<domain>.com"

objCDOSYSCon.Fields("") = 25

objCDOSYSCon.Fields("") = 2

objCDOSYSCon.Fields("") = 60


‘Update the CDOSYS Configuration

Set objCDOSYSMail.Configuration = objCDOSYSCon

objCDOSYSMail.From = "configmgr@<yourdomain>.com"

objCDOSYSMail.To = strRecipient

objCDOSYSMail.Subject = strSubject

‘Set the e-mail body format (HTMLBody=HTML TextBody=Plain)

objCDOSYSMail.TextBody = strMessage

‘Send the e-mail


‘Close the server mail object

Set objCDOSYSMail = Nothing

Set objCDOSYSCon = Nothing

End Sub

Share This Post

1 Comment

  1. Hi Joe I had a question about your helpful post. I have used your two scripts and added them to my TS. The first script (step in my TS) that prompts the user for the email address it is still sitting there but the prompt does not appear. When I created the sccm package for this script I set the program to run whether or not the user is logged in and I cant allow the user to interact with the program because the program become unavailable in the TS for selection. I think the pop up is not being displayed and it is now sitting at that step. How did you go about doing this? Thanks Yamini

Leave a Reply