Skip to content

Instantly share code, notes, and snippets.

@pcrockett-pathway
Created July 27, 2021 14:09
Show Gist options
  • Save pcrockett-pathway/c066fb8e23284c4cfab2dc8c6a48e0af to your computer and use it in GitHub Desktop.
Save pcrockett-pathway/c066fb8e23284c4cfab2dc8c6a48e0af to your computer and use it in GitHub Desktop.
Invoke a Discord Webhook from PowerShell
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[string]$WebhookUrl,
[Parameter(Mandatory=$True)]
[string]$Content
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 5.0
# For more details of what you can put in the payload, check out
#
# https://discord.com/developers/docs/resources/webhook#execute-webhook
#
$payloadDto = [PSCustomObject]@{
content = $Content
}
$payloadJson = $payloadDto | ConvertTo-Json
Invoke-RestMethod -Uri $WebhookUrl `
-Body $payloadJson `
-Method "POST" `
-ContentType "application/json" `
-UseBasicParsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment