Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send Message to Slack via PowerShell
Method to send webhook into Slack.
Method to set message into Slack.
.PARAMETER webhookUrl
Url of the webhook
Text to be sent
.PARAMETER channel
Name of the channel
Name of the bot, default "webhookbot"
Emoji icon, default ":ghost:"
Send message to general channel: SendMesssageToSlack "*" "Hi!" "#general"
Send message to general channel with botname: SendMesssageToSlack "*" "Build failed!" "#general" "Build watcher"
Send message to general channel with botname and its emoji: SendMesssageToSlack "*" "Build failed!" "#general" "Build watcher" ":rage:"
Function SendMesssage ([string] $webhookUrl, [string] $text,[string] $channel, [string] $botName="webhookbot", [string] $emoji=":ghost:") {
$body = @{
channel = $channel;
username = $botName;
text = $text;
icon_emoji = $emoji
$result = (Invoke-RestMethod -Method Post -Uri $webhookUrl -Body (ConvertTo-Json $body))
Write-Host $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment