OK I got this to work after a lot of searching.
Not my code, I combined some online to make this work.
When run, it takes a screenshot and then creates a ticket with the screenshot attached.
We are using it on locked down systems on our shop floor.
My future plan is to add a popup test box for them to enter in details about their issue.
Thank you!
$File = "$env:TEMP\Screenshot.png"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Screen.Width, $Screen.Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Screen.Left, $Screen.Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File)
$fileBin = $null
$fileBin = [IO.File]::ReadAllBytes($File)
$fileEnc = $null
$fileEnc = ([System.Text.Encoding]::GetEncoding("iso-8859-1")).GetString($fileBin)
$boundary = $null
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`n"
$bodyLines = $null
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"Action`"$LF",
"AddTicket",
"--$boundary",
"Content-Disposition: form-data; name=`"Subject`"$LF",
"Test",
"--$boundary",
"Content-Disposition: form-data; name=`"Description`"$LF",
"Test",
"--$boundary",
"Content-Disposition: form-data; name=`"Type`"$LF",
"Default",
"--$boundary",
"Content-Disposition: form-data; name=`"Priority`"$LF",
"High",
"--$boundary",
"Content-Disposition: form-data; name=`"Username`"$LF",
"domain\user",
"--$boundary",
"Content-Disposition: form-data; name=`"Team`"$LF",
"IT Infrastructure",
"--$boundary",
"Content-Disposition: form-data; name=`"Files`"; filename=`"Screenshot.png`"",
"Content-Type: application/x-msdownload",
"",
$fileEnc,
"--$boundary--$LF"
) -join $LF
$url = "http://helpdesk.Company.com/api.aspx?Key=APIKEY"
Invoke-RestMethod -Uri $URL -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -TimeoutSec 20 -Body $bodyLines
Remove-Item $File -Force