
PowerShell Basics: Send Slack Alert to Channel
If you work with Slack Channels, you may have a need to setup alerts into a channel. You can kick this off easily with PowerShell easily! This can be handy if you want to alert all users in the #helpdesk channel for instance of an upcoming maintenance, or you want a scheduled alert ran from a domain controller to remind your team to reboot it on Tuesday.
This can easily be accomplished with PowerShell. Before we start, you need to make sure you have a Slack Webhook created, and the correct permissions to post to the channel you want the Slack Webhook to send to.
Once you’ve created your Slack webhook, it’s time to create your PowerShell payload.
This script will need ran as administrator or if you are setting this up using Windows Schedule task, make sure you have the correct permissions setup.
$payload = @{
"channel" = "#dave-cool-channel"
"text" = "*Upcoming DNS Outage:*
Scheduled alert: Upcoming DNS outage tomorrow night at 9pm EST. So please add this to your schedule"
"username"= "Daves Helpdesk Alert"
"icon_emoji"= ":carebear:"
}
Invoke-WebRequest -UseBasicParsing `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "https://hooks.slack.com/services/T0ACBE211/GETYOUROWNWEBHOOKFORTHIS"
This sends the message to Slack like this:
Few things to note:
- Yes, you can change the emoji, in my case Im using a custom Carebear that I manually uploaded to Slack.
- You can change the username to whatever you want.
- Text supports markup. Using ** for instance will bold the text.
Hope you find this helpful!
Categories
Recent Posts
- PowerShell: How to Add an Alias to Every Users Mailbox and Groups in Microsoft 365
- Slack: Disable Entra ID User using a slash command.
- Slack: Retrieve Entra ID (MS365) User Information with a slash command.
- Jira Cloud: Disabling Entra ID User Accounts via Automation and Microsoft Runbook
- Jira Cloud: Restart an Azure VM using JSM Assets and Automation