function Send-MessageWithAttachment {
        Sends an HTTP POST to the Pushover API using an HttpClient
        When sending an image attachment with a Pushover message, you must use multipart/form-data
        and there doesn't seem to be a nice way to do this using Invoke-RestMethod like we're doing
        in the public Send-Message function. So when an attachment is provided to Send-Message, the
        body hashtable is constructed, and then sent over to this function to keep the main
        Send-Message function a manageable size.

    param (
        # Specifies the various parameters and values expected by the Pushover messages api.

        # Specifies the image to attach to the message as a byte array

        # Optionally specifies a file name to associate with the attachment
        $FileName = 'attachment.jpg'

    begin {
        $uri = $script:PushoverApiUri + '/messages.json'

    process {
        try {
            $client = []::new()
            try {
                $content = []::new()
                foreach ($key in $Body.Keys) {
                    $textContent = []::new($Body.$key)
                    $content.Add($textContent, $key)
                $jpegContent = []::new($Attachment)
                $jpegContent.Headers.ContentType = []::new('image/jpeg')
                $jpegContent.Headers.ContentDisposition = []::new('form-data')
                $jpegContent.Headers.ContentDisposition.Name = 'attachment'
                $jpegContent.Headers.ContentDisposition.FileName = $FileName

                Write-Verbose "Message body:`r`n$($content.ReadAsStringAsync().Result.Substring(0, 2000).Replace($Body.token, "********").Replace($Body.user, "********"))"
                $result = $client.PostAsync($uri, $content).Result
                Write-Output ($result.Content.ReadAsStringAsync().Result | ConvertFrom-Json)
            finally {
        finally {