How to Send Messages to Slack with PowerShell

Collaboration software tools are present in some shape or form in every workplace and if properly implemented and organised will give team members the opportunity of working together not only in an efficient way, but getting the job done while having fun!

Integration with these tools is not just desirable, it’s sometimes required. The nature of instant messaging communication in each workplace my vary depending on the content and information can be volatile and informal or more persistent and organised.

Using Powershell to integrate with Teams or Slack

One of the most popular articles here on scripting library was using PowerShell to send messages to Microsoft Teams. The scenario for the integration was scheduling a script (every 5 minutes) written in PowerShell that checked in Active Directory for any Locked Out user and if that was the case then sending the notification on the MS Teams Channel to inform the Support or Operations Teams involved within the organisation.

I strongly recommend you to read this article because in this one I will give for granted that you’re already familiar with SAAS applications and WebHooks.

How to trigger incoming webhooks in Microsoft Teams with Powershell

Slack was the next popular tool to cover

It may seem obvious, but I think that is sometimes required to show on different tools how can we reach the same goal and in just a few steps is possible to have the same integration completed.


How to configure Slack to receive messages via WebHooks

  1. Open your Slack Channel
  2. Click on Add Apps
  3. Search for Incoming WebHooks
  4. Complete the integration Settings choosing the Channel where you want to post and copy the Webhook URL to paste it later in the PowerShell script below.
  5. Save your settings

Useful Resources from the official documentation

Powershell Script

I’ve revisited the script created in the previous article and simply adapted for Slack, the only meaningful change are on the posted JSON and the different WebHook URL as you probably expect:

This will be the message received in SLACK

I hope you’ve found this article interesting and if you have any question or feedback feel free to contact me, as usual, my code is available on my GitHub repository.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.