cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
stol
Engaged Sweeper II
Hello,
Does anyone have a powershell script that will create a ticket with a file attached?
I'm having a issue with the attach file part. I need help!


Maybe someone could create a function for all the ticket features!

Thank you!
1 REPLY 1
stol
Engaged Sweeper II
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

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now