March 12 2010

Send SCCM task sequence email report

I wanted an easy way to know if OS deployments were failing or succeeding. We’ve come up with a good way of sending an email outlining task sequence completion status.

  • In SCCM, create a Status Filter rule by going to Site Database – Site Management – Primary Site – Site Settings – Status Filter Rules.
  • On the general tab, use Component : Task Sequence Manager, Message ID: 11170 . (11170 signifies failure, 11171 is for success.)
  • On the actions tab, tick Run a program and use something like ‘powershell.exe D:SCRIPTSTS_Email_Notification.PS1 %msgsys’.

TS_Email_Notification.PS1 should contain the following:

param([string]$strComputerName)
$erroractionpreference = "SilentlyContinue"
$strSMTP = "mail.domain.com"
$strSubject = "SCCM OSD Deployment Completed for $strComputerName"
$strBody = "$strComputerName has Completed the Task Sequence"
$MailMessage = New-Object System.Net.Mail.MailMessage
$MailMessage.IsBodyHtml = $true
$SMTPClient = New-Object System.Net.Mail.smtpClient
$SMTPClient.host = $strSMTP
$Sender = New-Object System.Net.Mail.MailAddress("sender@domain.com", "Sender")
$Recipient = New-Object System.Net.Mail.MailAddress("recipient@domain.com", "Recipient")
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender
$MailMessage.Subject = $strSubject
$MailMessage.To.add($Recipient)
$MailMessage.Body = $strBody
$SMTPClient.Send($MailMessage)

You just need to adjust the above Powershell script for your mail settings and you will now receive an email each time there is a successful or failed OS deployment.



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------


Tags: , , , , , , , , ,

Posted March 12, 2010 by danovich in category "Powershell", "SMS / SCCM

0 COMMENTS :

  1. By bizzarro on

    i’ve set up a status alert like you said with the script but it doesn’t run it. I changed it to look for the message ID only 10008 for completed successfully.

    I configured the script and ran the command line manually and it works. But after the job runs successfully it never runs the other program.

    Is there anything I need to look at or if there’s a log I can view to see on why it didn’t run.

    Reply
  2. By danovich (Post author) on

    bizzarro, I was also having inconsistent resulting using the powershell script, so I’ve re-written it with VBScript and is as follows:

    ‘START VBS

    Dim sComputerName
    Set args = WScript.Arguments
    sComputername = args.Item(0)

    Set objMessage = CreateObject(“CDO.Message”)
    objMessage.Subject = “SCCM OS deployment failed for ” & sComputername
    objMessage.From = “sender@domain.com”
    objMessage.To = “recepient@domain.com”
    objMessage.TextBody = sComputername &” has failed a task sequence”

    ‘==This section provides the configuration information for the remote SMTP server.
    ‘==Normally you will only change the server name or IP.
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

    ‘Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “mail.domain.com”

    ‘Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    (“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25

    objMessage.Configuration.Fields.Update

    ‘==End remote SMTP server configuration section==

    objMessage.Send

    ‘ END VBS

    The action for the status filter rule is “CSCRIPT.EXE D:SCRIPTSemail.vbs %msgsys” with Message ID as “11170” and Component as “Task Sequence Manager”

    Reply
  3. By bizzarro on

    Actually the problem was that I can’t use it as a command line within the Actions tab. I put the command line into a .cmd file to run after the job is done. That works, but the %msgsys doesn’t seem to be working. It says “msgsys” rather than the computer name from what I read in the documentation on the command lines.

    Thanks,

    Harvey

    Reply
  4. By danovich (Post author) on

    Have you tried just using ‘CSCRIPT.EXE D:SCRIPTSemail.vbs %msgsys’. I am sure this works. If you start using batch files you will lose the parameters that are being fed into the command.

    Reply
  5. By bizzarro on

    Sorry, I was referring to your original Powershell script when I ran that command.

    I just piece together one in VB from another code I found online, should of just came here instead to use yours. The only problem I have in my VBscript is that I can’t set the argument to the strComputer variable. It says object or method not supported Item. If I leave the argument as is and use that as the variable it works fine. For this case I only need one argument but wonder why other posted scripts work allow people to set the variable?

    Thanks.

    Reply
  6. By bizzarro on

    I have it working like your script and see where the error is in theirs. They reversed the objARgs.Item(0)= StrComputer instead of StrComputer = ojbArgs.Item(0) like you have it. That resolved that issues and now I have it working, thanks.

    Harvey

    Reply
  7. By alexandh on

    I am trying to implement this, but it is not working. If I run the from a command prompt, it goes thru, so my setup in the status filter rule must be incorrect. I had to type in “task sequence manager” for the component, as it was not available as a drop down. Running SCCM R3. Any ideas?

    Reply
  8. By tpullins on

    I also do not see Task Sequence Manager in the Component drop down list… SCCM 2007 R2

    Reply
  9. By McRaae on

    I am also trying to implement this, but do not see “Task Sequence Manager” in the Component drop down list. I typed it manualy, byt it dosn’t seem to be working. I have a lot of TS errors but no mail. I have teste the mail script manualy and it works.

    SCCM 2007 R2

    Reply
  10. By Tronni on

    I’ve have the same issue as above. I cant find “Task Sequence Manager” in the drop down list.

    Reply
  11. By Napandee on

    Hello!

    First of all thanks works like a charm 🙂

    However in my SCCM the script sends multiple emails for the same client?

    Sometimes it can be 2mins between them and sometimes around 30mins.

    Any idea what to look for?

    Keep up the good work!

    Reply
  12. By Napandee on

    Ofc about 1h after I posted I found the “problem”

    The status filtering rule is doing as it’s been told! It searches for the success code 11171 but imagen if you install some software via TS besides the OSD…..

    I modified my status filtering rule to search for my Windows 7 installation OSD package ID and then the spam stopped 🙂

    Hope this helps some1!

    Reply

Leave a Reply