Windows PowerShell

Create a HPSM9 incident with an attachment using PowerShell


One of our valuable customer asked a script to create a HPSM9 incident with a screen shot! Yes, it is really easy if we understand the WSDL! With no wait here is the snippet

#region Attaching a screen shot
$Stream = [System.IO.MemoryStream]::new()
$Image = [System.Drawing.Bitmap]::new("C:\Temp\Pictures\easy.jpg")
$Image.Save($Stream, [System.Drawing.Imaging.ImageFormat]::Jpeg)
$ImageBytes = $Stream.ToArray()

$Attachment = New-Object ($NameSpace + ".AttachmentType")
$Attachment.action = "add"
$ = "EasyDemo.jpg"
$Attachment.len = $ImageBytes.Length
$Attachment.contentId = "attachment"
$Attachment.attachmentType = "Image/Jpeg"
$Attachment.Value = $ImageBytes
$IncidentInstanceType.attachments = $Attachment

The documentation for HPSM9 is here! Get the full script from GitHub!


Leave a Reply

Your email address will not be published. Required fields are marked *