Powershell API with HTML table in description

Powershell API with HTML table in description

I have trying to create a ticket using API where the description is populated by a variable with the convertto-html.

I am pulling a list of accounts from AD and want to generate a ticket with this information. My code looks like this:

$adaccounts = get-ADUser -* | Select displayname,manager | Convertto-html | Out-String

# Set system parameters - change these details to suit your system environment
$sdphost = "URL"
$techkey = "Key"

# Set API module URL, operation and input data
$url = $sdphost + "sdpapi/request"
$method = "POST"
$operation = "ADD_REQUEST"

$inputdata = @"
{
    "operation": {
        "details": {
"requester": "AD Reports",
"subject": "Inactive User Accounts",
            "description": "$adAccounts",
            "requesttemplate": "default",
        }
    }
}
"@

$params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY=$techkey;format='json'}

$result = Invoke-WebRequest -Uri $url -Method $method -Body $params

write-host $result


I keep getting this error:

{"operation":{"result":{"status":"Failed","message":"Error when performing - ADD_REQUEST - Unterminated string at character 332 of {\r\n    \\\"operation\\\": {\r\n        \\\"details\\\": {\r\n\t\t\t\\\"requester\\\": \\\"AD Reports\\\",\r\n\t\t\t\\\"subject\\\": \\\"Inactive User Accounts\\\",\r\n            \\\"description\\\": \\\"

                  New to ADSelfService Plus?