Created
July 27, 2021 14:09
-
-
Save pcrockett-pathway/c066fb8e23284c4cfab2dc8c6a48e0af to your computer and use it in GitHub Desktop.
Invoke a Discord Webhook 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
[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