Created
April 22, 2016 14:31
-
-
Save aaldrich29/18cf8507e145c96ad0957df95f4eed88 to your computer and use it in GitHub Desktop.
Send Slack Message from PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Send-SlackMessage { | |
# Add the "Incoming WebHooks" integration to get started: https://slack.com/apps/A0F7XDUAZ-incoming-webhooks | |
param ( | |
[Parameter(Mandatory=$true, Position=0)]$Text, | |
$Url="https://hooks.slack.com/services/xxxxx", #Put your URL here so you don't have to specify it every time. | |
# Parameters below are optional and will fall back to the default setting for the webhook. | |
$Username, # Username to send from. | |
$Channel, # Channel to post message. Can be in the format "@username" or "#channel" | |
$Emoji, # Example: ":bangbang:". | |
$IconUrl # Url for an icon to use. | |
) | |
$body = @{ text=$Text; channel=$Channel; username=$Username; icon_emoji=$Emoji; icon_url=$IconUrl } | ConvertTo-Json | |
Invoke-WebRequest -Method Post -Uri $Url -Body $body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing, been using a while
Recently discovered Rocket.chat as alternative to slack which is 'supposed' to work where you can just replace the webhooks ...etc This works in other apps but have issues w/ this script where the body doesnt get sent and the channel doesn't override the default channel of the webhook? Any ideas by chance?