How can I invoke a SCOM Recovery Task from a REST call?

I’m trying to execute a REST call from PowerShell to run a SCOM Recovery Task.

I’ve read as much of the REST API documentation and other forums that I could find on this particular subject and I feel like I’m close to a working script, but I keep stumbling at the same point.

Script:

# NOTE SOME VALUES HAVE BEEN CHANGED FOR SECURITY/PRIVACY.

$Cred = Get-Credential

# Set header and the body
$scomHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')
$bodyraw = "Windows"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json

#Authenticate
$uriBase = 'http://<scomserver>/OperationsManager/authenticate'
$auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomheaders -body $jsonbody -Credential $Cred -SessionVariable websession

$uri = "http://<scomserver>/OperationsManager/data/submitTask"

$method = "POST"

$query = @(@{ "monitoringObjectIds"= "monitori-ngOb-ject-Ids0-000000000000",
              "parametersWithValues" = "",
              "taskId" ="taskId00-0000-0000-0000-000000000000"
})
$jsonquery = $query | ConvertTo-Json
$Response = Invoke-RestMethod -Uri $uri -Method $method -Body $jsonquery -ContentType "application/json" -credential $Cred -WebSession $websession
$alerts = $Response.Rows
$alerts

Error:

Invoke-RestMethod : {"message":"The request is invalid.","modelState":{"request.monitoringObjectIds":["An error has 
occurred."]}}
At C:\Users\<userId>\<folder>\SCOM_REST_Call_Test_v1.ps1:37 char:13
+ $Response = Invoke-RestMethod -Uri $uri -Method $method -Body $jsonqu ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio 
   n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I’m new to SCOM, but familiar with PowerShell, so I’ve learned some commands along the way to identify the ID values I am using in SCOM.

I’ve tried different values from other tasks, but keep getting the error.

Has anyone ever tried doing things this way? I am aware of other methods, but I’m testing this approach for a particular task (a small component to a larger project).

Any assistance is greatly appreciated, as I’ve been staring at the same code for far too long and I’m probably looking right at the issue and just can’t see it.

EDIT: Formatting