I had a client ask me if it was possible to ‘make’ ConfigMgr 2012 send an email when a workstation has finished building.

They are using ConfigMgr 2012 to deploy their build.

I have done this before using a VB script, but thought I would try and do it using PowerShell.

There are two parts to this, first identifying a way to see that the OS deployment has completed (and being able to run an action) the second is send an email form the command line.

I am going to use ‘Status Filter Rules’ there are other ways to achieve this, but this is the method I choose to use.

When a task sequence has completed it generates a status message like this ‘The task sequence manager successfully completed execution of the task sequence’

It will have a Message ID equal to 11171 and a Package ID that is equal to the Package ID of the task sequence.

Create a new ‘Status Filter Rule’ and set the following criteria

Source : Client

Message ID : 11171

Property : Package ID

Property Value : ‘Package ID of the task sequence’

On the Actions tab select ‘Run a program’

Program : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "path to script\ScriptName.ps1" -ComputerName %msgsys -TS "Windows Build Task Sequence"

Here is the script

Param(
     $ComputerName,
     $TS
     )
$Subject =  "$TS ran successfully on $ComputerName"
$MessageBody = @"
$TS was successful on $ComputerName
"@
$From = "Administrator <administrator@domain.com>"
$To = "Administrator <administrator@domain.com>"
$SMTPServer = "smtp.domain.com"

 
Send-MailMessage -Subject $Subject -Body $MessageBody -From $From -To $To –SMTPServer $SMTPServer

 

This will create a message with the subject ‘Windows Build Task Sequence ran successfully on ComputerName’

And with the body text ‘Windows Build Task Sequence was successful on ComputerName’

 

NB: For this to work you need to allow anonymous users to connect to the receive connector

If you want to do expand it, try creating one for Message ID 11170, this signifies a failure

 

P.S. If you want to figure out how to do this yourself, use the reference links that I used:

The reference material I used was
http://www.vmadmin.co.uk/microsoft/54-powershell/237-powershellemailsmtp
http://exchangeserverpro.com/powershell-how-to-send-email

Anonymous