I originally saw Terence Beggs post about sending messages through Microsoft Teams. Not having Teams, I wanted to send the message through Slack instead. This pretty much operates in the same fashion but had to be tweaked in order to work properly. These script(s) are a very minor part of our SCCM environment, but I really love getting notified when either in-place upgrades are complete, or computers are imaged.
Slack Application Setup
The first step is to head over to the Slack API site and create an app. Name your app as you please.
After you create your application, you’ll need to create an incoming webhook. You’ll assign it to a channel in Slack, so I recommend creating a new one for notification. That way other people can mute the channel if it gets too noisy. Make note of your webhook URL as we’ll need this later in the PowerShell script.
SCCM/Task Sequence Setup
Now onto SCCM. Use the Get-TSDuration.ps1, and slack_sccm_message.ps1 located here, and modify the main slack_sccm_message to include your webhook URL in the URI variable. Create a package (no program) for the folder that includes both scripts. Distribute the package to the applicable distribution points in your environment. Get-TSDuration.ps1 will set task sequence variables, based on a parameter, for the start and end of a task sequence. It’ll later be used in a time span to get the total time for the task sequence.
In your task sequence, create a step to Run a PowerShell Script. Select the package you just created, use the script name and Specify the Start parameter.
Do the same thing for the end of your task sequence, but obviously add the step to the end of the task sequence, and replace the Start parameter with End. If you’re doing any sort of error handling for failures, you might need a second End parameter for the error handling portion. This will also hold true for the slack message script if you want to send messages for Task Sequence failures as well.
Add the slack_sccm_message script right after your Get-TSDuration ending scripts. I’m using a PassFail parameter to format the message differently based on if the task sequence succeeds or fails.
What you should wind up with is a nicely formatted slack message like this:
You’ll notice that there are links to images for passing and failing task sequences, task sequence variables, and static text. This can obviously be formatted to your liking. Let me know what other changes you’ve come up with, or if you’re adding something additional that you think is helpful to know.