Description
When running the following code I was getting the error, "Invoke-RestMethod: Error - Could not add task: The property 'ScheduledTime' cannot be found on this object. Verify that the property exists and can be set."
# Get jobs
$BodyPayload = @{
TenantFilter = "AllTenants"
ShowHidden = $true
}
$AllJobs = Invoke-CIPPRestMethod -Endpoint "/api/ListScheduledItems" -method POST -Body $BodyPayload
$Job = $AllJobs[0]
$UpdatePayload = @{
RowKey = $Job.RowKey
Name = $Job.Name
tenantFilter = $Job.Tenant
Hidden = $Job.Hidden
Command = $Job.Command
Parameters = $Job.Parameters
Recurrence = $Job.Recurrence
ScheduledTime = $NewScheduleTime
}
Invoke-CippRestMethod -Endpoint '/api/AddScheduledItem' -Method 'POST' -Body $UpdatePayload|Out-Null
Upon inspection I found Invoke-CIPPRestMethod defines Body as a hashtable array:
[hashtable[]]$Body = @{},
After changing it to the following, the command completed successfully:
Environment data
Module Version Number: v10.5.5
CIPP Backend version number: v10.5.6
Description
When running the following code I was getting the error, "Invoke-RestMethod: Error - Could not add task: The property 'ScheduledTime' cannot be found on this object. Verify that the property exists and can be set."
Upon inspection I found Invoke-CIPPRestMethod defines Body as a hashtable array:
After changing it to the following, the command completed successfully:
Environment data