When deploying an operating system with SCCM / MEMCM, monitoring your deployment is crucial. You can use reports in a more dynamic way. Imagine receiving an email saying “Hey your deployment is complete. The computer can be delivered to the client”. SCCM can send an email based on a specific status message generated by the site server. And this is exactly what will be done in this blog post.
SCCM records everything action in Status Messages. You are probably familiar with the tons server logs files but SCCM also records everything on the site server itself. A quick look at the Status message shows that there’s tons of available information.
- In the SCCM Console
- Go to Monitoring / System Status / Status Message Queries / All Status Message
- Status Message shows all actions, there’s lots of valuable information in there
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
SCCM OSD Send Email – Status Filter Rules
We’ll use a Status filter rule to run our script.
It permits to do an action when a specific code is generated. In my example, I’ll use MessageID 11171 to run a Powershell script. MessageID 11171 means : Task Sequence completed
- In the Configuration Manager Console
- Open Administration / Sites / Status Filter Rules
- In Status Filter Rules window, click Create
- On the Create Status Filter Rule wizard, fill the following text boxes:
- Name : Task Sequence email
- Source : Client
- Message ID : 11171
- Property : Package ID
- Property Value – PS10000A (change the value with your TS ID). You can find your task sequence PackageID in the console. Software Library / Operating Systems / Task Sequences
- In the Action tab at the top
- Check Run a program and enter the following program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file D:\Scripts\OSD_Deployment_Success.ps1 -ComputerName %msgsys -TS “Windows 10 x64”
So we just told SCCM to run the PowerShell script when MessageID 11171 gets generated.
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 <email@example.com>" $To = "IT Administrator <firstname.lastname@example.org>" $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 to avoid 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)