Use PowerShell to post to a Slack channel with extra args


You need to create an application in Slack with incoming webhooks.

Enable the application and confirm your identity.

Copy that webhook.

Invoke the script with system variables to post extra content for alerts, automation, escalations, etc.

$message = "`n" + $args

Set-StrictMode -Version Latest

$payload = @{
  "channel" = "#alerts";
  "icon_emoji" = ":inbox_tray:";
  "text" = $(Write-output "$message");
  "username" = "User";

Invoke-WebRequest `
  -Uri "" `
  -Method "POST" `
-Body (ConvertTo-Json -Compress -InputObject $payload)



Leave a Reply

Your email address will not be published. Required fields are marked *