Skip to content

Instantly share code, notes, and snippets.

@marazt
Last active March 10, 2018 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marazt/04ab5e9b3b08e1a097a0 to your computer and use it in GitHub Desktop.
Save marazt/04ab5e9b3b08e1a097a0 to your computer and use it in GitHub Desktop.
Send Message to Slack via PowerShell
<#
.SYNOPSIS
Method to send webhook into Slack.
.DESCRIPTION
Method to set message into Slack.
.PARAMETER webhookUrl
Url of the webhook
.PARAMETER text
Text to be sent
.PARAMETER channel
Name of the channel
.PARAMETER botName
Name of the bot, default "webhookbot"
.PARAMETER emoji
Emoji icon, default ":ghost:"
.EXAMPLE
Send message to general channel: SendMesssageToSlack "https://hooks.slack.com/services/*" "Hi!" "#general"
Send message to general channel with botname: SendMesssageToSlack "https://hooks.slack.com/services/*" "Build failed!" "#general" "Build watcher"
Send message to general channel with botname and its emoji: SendMesssageToSlack "https://hooks.slack.com/services/*" "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