Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active February 13, 2021 01:09
Show Gist options
  • Save magnetikonline/11007e42d86f490b84f8 to your computer and use it in GitHub Desktop.
Save magnetikonline/11007e42d86f490b84f8 to your computer and use it in GitHub Desktop.
PowerShell push message to Slack incoming webhook.
Set-StrictMode -Version Latest
$payload = @{
"channel" = "#my-channel"
"icon_emoji" = ":bomb:"
"text" = "This is my message. Hello there!"
"username" = "Mr. Robot"
}
Invoke-WebRequest `
-Body (ConvertTo-Json -Compress -InputObject $payload) `
-Method Post `
-Uri "https://hooks.slack.com/services/HOOK_API_SLUG" | Out-Null
@pixelbath
Copy link

As an alternative to Invoke-WebRequest, you can use the (already built-in) Invoke-RestMethod:

Invoke-RestMethod -Uri "https://hooks.slack.com/services/HOOK_API_SLUG" -Method Post -Body $payload -ContentType "application/json"

@magnetikonline
Copy link
Author

Thanks @pixelbath, nicely noted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment