Over a short period of time, Slack communication has become one of the most popular platforms, and it's easy to see why. After all, the easy-to-use platform has an intuitive interface and a robust API with lots of apps that tie into many popular services such as Dropbox, Github and Trello. And it's fairly easy to create your own Slack integrations to use however you see fit.

By using Slack's API and a PowerShell module, you can integrate any kind of messaging you'd like to send to Slack via a simple PowerShell command. Here are some tips on how to establish a Slack channel as a notification hub for your team.

Custom Integration

First off, you'll need to create a custom integration. More specifically, you'll need to create an Incoming Webhook configuration. To do so, when logged into your Slack team, click on "Build" and then on "Make a Custom Integration." At the custom integration screen, click on incoming webhooks, select the channel to which your messages will be posted and click "Add Incoming WebHook integration."

Once you have the incoming webhooks integration created, you should make note of the webhook URI. You will need this URI when you are sending messages from PowerShell.

PSSlack Module

Next, you should install a copy of Warren Frame's PSSlack module. It's possible to establish a notification hub without the help of this module, but using it will save you a lot of time when it comes to figuring out how to interact with Slack's API via PowerShell.

When you're ready to send a message to your Slack channel with PowerShell, you should use the Send-SlackMessage function in the PSSlack module. While there are a couple of different ways to send a slack message, the easiest method may be to simply use the webhook URI. After you ensure that you have the PSSlack module loaded into your session, you can use the Send-SlackMessage function by specifying the webhook URI as well as the message text:

Send-SlackMessage -Uri <URI> -Text 'testing'

This will send the message to the channel that you have configured in your incoming webhook configuration on Slack. You can see below that the "user" that posted this message was "EO." That's due to the fact that the default name inside of the webhook configuration was changed.

You can use this technique in a lot of monitoring scripts. For example, if you have monitoring software that can kick off a PowerShell script, you no longer have to just rely on email or text messaging. If your team has a Slack channel open all day, you can now create a notifications channel setup to alert your entire team when a message is posted.

For example, here's a function you can call within your script:

Function Send-Notification {
        [string]$SlackWebhookURI = ''
	Send-SlackMessage -Uri $SlackWebhookURI -Message $Message

When you use this function, you no longer have to remember the webhook URI. Instead, you can send quick text notifications through Send-Notification.

There are quite a few other cool things you can do with the Slack API and the PSSlack module. By using this technique to implement Slack Communication into your monitoring solution, you can dive deeper into your own custom integration.

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!