How to assign a message header using Outlook REST API from PowerShell? (SingleValueExtendedProperties) RRS feed

  • Question

  • I am using powershell to construct a message body, and I am able to successfully send when using with invoke-RestMethod. I would like to add a custom header to the message, however when I attempt to do so I get an error:

    Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

    What's the proper formatting and object to use when assigning a message header? In this case I'm using a built-in O365 header.

    Here's the script:


    $Securepass=ConvertTo-SecureString -string $Password -AsPlainText -Force
    $Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $User,$Securepass
    $ContentType = "application/json;odata.metadata=full"
    $uri = ""
    $host.UI.RawUI.WindowTitle = $User

            ""Subject"": ""Test Subject"",
            ""Body"": {
                ""ContentType"": ""HTML"",
                ""Content"": ""This is the message body""
            ""ToRecipients"": [
                        ""Address"": """"
            ""SingleValueExtendedProperties"": [
                    ""PropertyId"":""String {00020386-0000-0000-C000-000000000046} X-Ms-Exchange-Organization-Dlp-SenderOverrideJustification"",
                    ""Value"":""TransportRule override""

    write-output $MessageBody
    Invoke-RestMethod -Uri $uri -Method Post -Credential $cred -Body $MessageBody -ContentType $contentType
    Saturday, April 8, 2017 12:16 AM

All replies