Created
May 4, 2021 13:22
-
-
Save royashbrook/a99528709418bde046fd0cfdaf102081 to your computer and use it in GitHub Desktop.
Post a text file to a discord webhook
This file contains 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
function Submit-TextFile($filePath,$Uri){ | |
$filename = (Get-ChildItem $filePath).Name | |
$filecontents = Get-Content $filePath -raw | |
$boundary = [guid]::NewGuid().ToString() | |
$contentinfo = "Content-Disposition: form-data; name=`"file`"; filename=`"$filename`"`nContent-Type: text/html; charset=utf-8`n" | |
$body = "--$boundary`n$contentinfo`n$filecontents`n--$boundary--`n" | |
$params = @{ | |
Uri = $Uri | |
Body = $body | |
Method = 'Post' | |
ContentType = "multipart/form-data; boundary=$boundary" | |
} | |
Invoke-RestMethod @params | |
} | |
#generate a random file to test with | |
$randomlogfile = "{0:yyyyMMddhhmmss}.txt" -f (get-date) | |
"Random Data`n--------------`n" > $randomlogfile | |
0..20|%{[guid]::NewGuid().ToString()>>$randomlogfile} | |
$Uri = 'yourwebhookurl' | |
$filePath = (Get-Item $randomlogfile).FullName | |
# call the function | |
Submit-TextFile $filePath $Uri |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment