Maybe you should try to use dedicated discord module https://github.com/EvotecIT/PSDiscord
#Help w Discord Webhook With PowerShell
1 messages · Page 1 of 1 (latest)
anything more on this? none of this seems to be doing what i'm trying to do (Following code can send a message to Discord. It changes Author of the message, adds an image as thumbnail and picture at the same time. It also turns the avatar name and logo.)
maybe i'm getting somewhere /shrug
The arguments to invoke-restmethod -- just use regular hashtables, don't convert to objects, don't convert to json.
I don't know if the API changed this part -- this is how you could do it before .
If you know the curl request needed for the API, it's easy to convert it to IRM.
https://ninmonkeys.com/blog/2021/01/22/creating-a-discord-webhook-in-a-few-lines-of-powershell/
summaries
Here's cleaner way, for summaries
function get_ReportForMonth {
param( [string]$Label )
"${Label}_report_a"
"${Label}_report_b"
"${Label}_report_c"
}
$summaries = @(
get_ReportForMonth '2022-01-01'
get_ReportForMonth '2022-02-01'
get_ReportForMonth '2022-03-01'
)
$summaries
$payload = [PSCustomObject]@{
content = $summaries | Select-Object `
start,
end,@{Label = 'change'; Expression = { '{0:$#,##0}' -f $_.change}}
}Invoke-restmethod -Uri $hookUrl -Method Post -Body ($payload | ConvertTo-Json) -Headers @{ "Content-Type" = "application/json"
What endpoint are you using?
I think select / PSCO, and ConvertTo-Json are part of the problem
not sure if that will help, i am not familiar with powershell whatsoever so not exactly sure how to answer "What endpoint are you using? "
by endpoint I mean which REST API are you calling? https://discord.com/developers/docs/resources/webhook#execute-webhook
that repo has a folder of some examples, and example tests https://github.com/EvotecIT/PSDiscord/blob/master/Tests/Send-DiscordMessage.Tests.ps1
hmm, do you mean this?
do any of them seem to be doing what i am trying to do? i couldnt make much of the examples for my purposes
not sure why this is such a pain, working script that i want to take the output instead of the table and just the data and send in a discord message
As far as I can see you're trying to send a table to Discord. To do this you need to convert your "data" into Discord format, as it doesn't accept table directly. You have to either do it via Facts and build your table yourself
or maybe try and do $YourData | Format-Table | Out-String
and send that, see if will show properly
I just tested my code, it still works. there's other more advanced output in the docs
Note, that is a webhook