Send an Email when OSD Completes a Deployment

Benoit LecoursPowershell, SCCM31 Comments

Did you know that SCCM can take an action when a specific message is generated on the site server?

SCCM records everything it does. You are probably familiar with the tons of logs files but SCCM also record everything on the site server itself.

A quick look to the Status message shows that there’s tons of available information.

Monitoring / System Status / Status Message Queries / All Status Message :

sccm osd send email

As you can see, there’s lots of valuable information in there.

sccm osd send email

Yeah great !… now what ? Using the power of PowerShell, I tell SCCM to send an email each time an event is generated. With imagination, you can do pretty cool stuff in there

How to do that ? 1 simple word ! “Status….filter….rules”… ok ! 3 words.

It permits to do an action when a specific code is generated. In my example, I’ll use MessageID 11171 to generate a powershell. (11171 = Task Sequence completed)

  • Configuration Manager Console, open Administration workspace
  • Select Sites
  • Select Status Filter Rules
  • In Status Filter Rules window, press Create
  • On the Create Status Filter Rule wizard , you need to fill the following text boxes:
  • Name – “Task Sequence email“
  • Source – Client
  • Message ID – 11171
  • Property – Package ID
  • Property Value – PS10000A (*****change that with your TS ID*****)

sccm osd send email

In the Action tab :

  • Run a program : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file D:\Scripts\OSD_Deployment_Success.ps1 -ComputerName %msgsys -TS “Windows 7 x64”

sccm osd send email

So we jsut told SCCM to run the powershell script when MessageID 11171 gets generated. How cool is that?

Here’s the Powershell script used for that :

Param($ComputerName,$TS)

$Subject = “$TS was successful on $ComputerName”

$Message = “$TS was successful on $ComputerName”

$From = “IT Administrator <from@you.com>”

$To = “IT Administrator <destination_email@you.com>”

$SmtpServer = “your.smtp.server”

Send-MailMessage -Subject $Subject -Body $Message -From $From -To $To -SmtpServer $SmtpServer

Change the variable ($Subject,$Message,$From,$To,$SmtpServer) to fit your environment.

Bonus tip #1 : Test the powershell script locally before running it and see with your Exchange Administrators if you gets this error “Send-MailMessage : Unable to connect to the remote server”.

Bonus tip #2 : Error “File test.ps1 cannot be loaded because the execution of scripts is disabled on this system”. This is because your Powershell execution policy is not configured correctly (hint: Get-ExecutionPolicy -list)

sccm osd send email

31 Comments on “Send an Email when OSD Completes a Deployment”

  1. Pingback: Have ConfigMgr send an email after deployment (including log parsing) – Deployment Research

  2. Benoit,

    Hopefully, you’re still seeing comments for this post!

    I too appreciate you & SCDudes for all the great info.
    One question on this post. We are using it and is wonderful.
    Our only issue is that UNKNOWN computers always say their MININT-xxxxxx name
    instead of the OSDComputerName (which we prompt for directly after PXE boot).

    The %msgsys give us the MININT-xxxxxx so is there any way to get the OSDComputerName
    into the email script?

  3. Did the guys that couldn’t get this to send email when running the TS but it worked when running manually ever solve it ? I have the same issue

  4. Bonjour Benoit,
    Thank you for the very useful article but I’m not sure if %msgsys works correctly on CM1710 which I’m using? It’s not returning the actual computer name but MINT-XXXX.

    ps. After 3 years of this article, people currently discussing it on SCCM Reddit!

  5. Old Post but I am running into a couple of issues.

    The first is that %msgsys is pulling the temp computer name “MNINT…” and not the name that I am using as the collection variable or the name that is reported to SCCM in it’s event log.

    The second is that the subject lines are not mailing what is between the quotes but garbling it with prepended question marks and only using the first word within the quotes “???Company” instead of “Company HP 745 win 7”

  6. Awesome guide!

    Is it possible to use wild cards (%) in the “system” field when creating a status filter rule? i.e. If system name is “2017-%” will it only trigger the PS1 if the client’s name start with ‘2017- ‘?

  7. Is it possible to include the computer model and serial number in this e-mail? I don’t know if SCCM has captured the data yet. I know the S/N is stored in SMS_G_System_PC_BIOS.SerialNumber

    1. In the powershell script you can use get-wmiobject (gwmi) to collect that information

      ex:
      Get-WmiObject Win32_Computersystem -computername $ComputerName| Select-Object -expand Model
      Get-WmiObject Win32_bios -computername $ComputerName| Select-Object -expand SerialNumber

      1. Hello,
        I been trying to added the Get-WmiObject Win32_Computersystem in the script but I keep getting the results of the SCCM server in the email as opposed to the client machine information. Would appreciate if you can share any tips of how I can use this command to pull the client information instead of the SCCM server.

        Thanks

  8. Is there a way I can run this for ANY task sequence? It would be awesome if there were some detail in the email as well. perhaps a link to the report with the field options already populated?

  9. This works great however during my task sequence I use a HTA to name the computer by location and first 8 of the SN… but I notice in the status logs it is still showing up as a MINT-xxxxx name. Any suggestions to actually have this log the actual name of the machine so it emails the actual PC name?

    1. Same issue I’m having. I’ve attempted a couple of suggestions but I can’t generate the true hostname consistently.

    2. I made quite a few changes to get it to work this way.

      First, I added this script as part of my task sequence instead of as a status filter. Done this way, it runs locally on the machine instead of on the Site Server.

      I followed the instructions here to accomplish this:
      http://schadda.blogspot.com/2012/01/sccm-2012-how-to-catch-errors-in-task.html

      Then I used task sequence variables to fill the $ComputerName and $TS (%OSDComputerName% and %_SMSTSPackageName%) instead of passing them as parameters.

      Then I added a step, prior to running the script, to set OSDComputerName to %_smstsmachinename% if OSDComputerName doesn’t already exist, and then use %OSDComputerName% instead of %_smstsmachinename% in all instances.

      With this setup. if OSDComputerName is set you should get that value. If it’s not set, you’ll get the MININT-xxxxx name. Plus it will work in any Task Sequence and will give you the name of the task sequence.

      I also added some of the other stuff that was talked about in that link (uploading the logs.)

      Then I made all of these steps into a child task sequence, and reference that child task sequence in my main task sequences.

  10. This is very cool!
    However, may I know what is the computer that executes the script (i.e. the computer that sends the email message).
    Is it the from site server or from the computer which the task sequence ran?

  11. This is worked with local install Exchange Server?
    i have error: Send-MailMessage : Cannot validate argument on parameter ‘Subject’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command a
    gain.
    At line:2 char:27
    + Send-MailMessage -Subject $Subject -Body $Message -From $From -To $To -SmtpServe …
    + ~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Send-MailMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SendMailMessage

  12. Hello, I tested it and ist working. I saw you are catching the computer Name by using %msgsys. I use the script to catch Errors and i want to catch the discription. Do you know who to do that?

  13. Hmm, I’m not actually getting the emails.

    Powershell policy is unrestricted.

    If I run the script manually then I get the email…!?

      1. Hi Benoit,

        I’m experiencing the same thing as Peter.

        I cannot receive the email from the event. I can manually run the command it sends the email.
        If I run under PSEXEC as system is works. (although to get this to work I had to add permissions for my SCCM server to send as myself (and then set the script to send as myself)) for this to work.

        any ideas?

        cheers,
        Kieran

        1. I have the same issue as well. I used PS exec to run as system and I get the email. But I’m not getting the email when the TS runs.
          I checked the box to write to the event log so I can see the event log that the correct status message is used. The policy is unrestricted, in my troubleshooting I also added -ExecutionPolicy Bypass still no emails.
          I’m running SCCM 2012 R2 SP1

  14. That’s awesome! A really great find. Quick question though, is there more field than the Computer name that can be passed in the script, so the email would contain the description and details from message? If so, how the variables are named? Would be really useful for message ID 11171 for task sequence failure.

    Really useful site by the way guys! Keep up the great work!

    1. Salut Martin !

      Sure, there’s a whole bunch of other parameters you could add. Check this link for the full list.

      Be sure to create an input parameters in the Powershell script and add the extra parameter in the Run a program filed of the Status Filter Rule.

      Thanks for the kind words about the blog 😉

  15. Pingback: How to monitor SCCM OSD | Houston Area Systems Management User Group

Leave a Reply

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