Send Message to Slack and Mattermost via PowerShell
This is one of the most searched and implemented logic when we talk about alerts or notifications. In our fast moving and busy schedule, we need alerts and notifications to directly come to us and update us for all kind of important updates. Gone are the days when we use to manually check and then notify the teams that there’s some kind of alert or notification for them.
Most of IT industry use Slack and Mattermost as their team collaboration software. In or out, you are always connected and updated by the means of these communication channels. People talk, people share, people discuss everything on these collaboration software.
In this post, lets discuss how to send message to these collaboration software via PowerShell.
In order to send the message to Slack/Mattermost, we write a small PowerShell script that will do the work for us. We’ll be leveraging Invoke-RestMethod of powershell for this.
Prerequisites
– Uri – Your webhook url
– Channel – Your Slack/Mattermost channel name
The above script is picked from GitHub.
Here, payload is JSON code that defines the message body.
Payload may be simple or it may represent some complex information in tabular form as:
In order to create URI or Webhook, please follow the procedure below:
– Slack: https://get.slack.help/hc/en-us/articles/115005265063-Incoming-WebHooks-for-Slack
– Mattermost: https://docs.mattermost.com/developer/webhooks-incoming.html
The above mentioned method is one of the simplest ways to send message on Slack or Mattermost. However, there are many other methods too to achieve this task. Please refer the below links for the same.
http://ramblingcookiemonster.github.io/PSSlack/
https://www.powershellgallery.com/packages/Mattermost/1.0.1/Content/Mattermost.ps1