Sending Email Notification from MDT 2012

In my recent rework of my Build and Capture sequences that are used for updating my reference images, I thought it would be nice to have an email notification when the process was done.  This post is to show how I did this.

I did this using Powershell’s Send-MailMessage cmdlet.  This provides a simple way to send a message via SMTP, and this MDT 2012u1 provides support for Powershell scripts it seemed a logical choice.  Since I wanted to send the message at the end of a Capture process, I needed to be able to send the message from the WindowsPE environment.

WinPE_PropertiesTo start, I needed to make sure I had Powershell included in my boot image.  Fortunately this is very easy to do with MDT.  In the deployment workbench right click the deploymentshare and choose “properties”  Click on the Windows PE tab and then on the “Fearures” tab within that.  Check the boxes for .NET frame work and Powershell as shown in the image.

After applying the change, right-click on the deployment share and choose “Update Deploymentshare” to rebuild the boot images.  Once that is completed, remember to update your PXE server to the new boot image, or replace your CDs if using media.

Now for the script.  The script is short, just three lines in fact :

$PSEmailServer = "smtp.example.com"
$Subject = "Task Sequence " + $TSEnv:TaskSequenceID " " has completed"
Send-MailMessage -to "Firstname Lastname <user@example.com>" -from "MDT <user@example.com>" -subject $Subject

This script will send a message with no body, and a subject that contains the name of the task sequence that called it.  You will need to change the smtp server information and the email addresses to suite your environment.  Save the script into the Scripts folder of the deploymentshare, and we are ready to add it to the task sequence. At the point in the task sequence where you wish the message to be sent, choose Add -> General -> Run PowerShell Script. In the “PowerShell Script:” field enter the following :

%scriptroot%\SendMessage.ps1

Change the name of the script to reflect the file name you gave it when you saved the script to the Scripts directory, and you are done!  To read more about the Send-MailMessage cmdlet, see the Technet documentation

2 thoughts on “Sending Email Notification from MDT 2012

  1. One additional note. When updating Windows PE to include Powershell, be sure to do it for both x86 and x64 if you are capturing images in both platforms. You can use the x86 media for the initial boot media for both platforms, but when the task sequence downloads Windows PE to prepare for the capture phase it will download whichever matches the platform you are capturing.

    I did all my initial testing in x86, and missed this detail. When the email notification did not work for my x64 build I realized my mistake 😉

  2. Good stuff!
    I modified this a bit to fit my needs. I am running a “for each” loop against a CSV containing all the email addresses. I have a HTML forum posted on share point so tech’s can register for notifications (adds tech email to CSV), or unsubscribe (removes email from CSV).

    FOR TEXT Notification – set a rule in outlook to redirect these emails to your cell number 5105559988@vtext.com. You could put the sms address directly into the script instead of email, but redirecting cleans up the notification (removes the characters added during transmission).

    Alltel
    [10-digit phone number]@message.alltel.com
    Example: 1234567890@message.alltel.com

    AT&T (formerly Cingular)
    [10-digit phone number]@txt.att.net
    [10-digit phone number]@mms.att.net (MMS)
    [10-digit phone number]@cingularme.com
    Example: 1234567890@txt.att.net

    Nextel (now Sprint Nextel)
    [10-digit telephone number]@messaging.nextel.com
    Example: 1234567890@messaging.nextel.com

    Sprint PCS (now Sprint Nextel)
    [10-digit phone number]@messaging.sprintpcs.com
    [10-digit phone number]@pm.sprint.com (MMS)
    Example: 1234567890@messaging.sprintpcs.com

    T-Mobile
    [10-digit phone number]@tmomail.net
    Example: 1234567890@tmomail.net

    US Cellular
    [10-digit phone number]email.uscc.net (SMS)
    [10-digit phone number]@mms.uscc.net (MMS)
    Example: 1234567890@email.uscc.net

    Verizon
    [10-digit phone number]@vtext.com
    [10-digit phone number]@vzwpix.com (MMS)
    Example: 1234567890@vtext.com

    Virgin Mobile USA
    [10-digit phone number]@vmobl.com
    Example: 1234567890@vmobl.com

Leave a Reply

Your email address will not be published. Required fields are marked *

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