-
Notifications
You must be signed in to change notification settings - Fork 214
Description
I'm using ConvertFrom-Json -AsHashtable to convert a json file to a hashtable and feeding this directly to the cmdlet. By design this makes ordered hashtables of all nested elements.
It was a huge pain in the butt to discover the root cause of the error was the ordered hashtable type. But the issue only occurs when choices or localizations is forced to be an ordered hashtable.
Here's an example that works (notice the first element of $questions is cast to be an ordered hashtable:
$accessPackageId = "aca61375-7c6c-4842-910f-1bba4bc7e894"
$localizations = @(
@{
text = "France"
languageCode = "en-US"
}
)
$choices = @(
@{
"@odata.type" = "#microsoft.graph.accessPackageAnswerChoice"
text = "France"
actualValue = "FR"
localizations = $localizations
}
)
$questions = @(
[ordered]@{
"@odata.type" = "#microsoft.graph.accessPackageMultipleChoiceQuestion"
sequence = "1"
isRequired = "true"
isAnswerEditable = "true"
text = "What country are you working from?"
isMultipleSelectionAllowed = "false"
choices = $choices
}
)
$params = @{
accessPackage = @{
id = $accessPackageId
}
displayName = "A Policy With Questions"
description = ""
allowedTargetScope = "allMemberUsers"
expiration = @{
type = "afterDuration"
endDateTime = $null
duration = "P90D"
}
requestorSettings = @{
enableTargetsToSelfAddAccess = $true
enableTargetsToSelfUpdateAccess = $true
enableTargetsToSelfRemoveAccess = $true
allowCustomAssignmentSchedule = $true
}
requestApprovalSettings = @{
isApprovalRequiredForAdd = $false
isApprovalRequiredForUpdate = $false
}
questions = $questions
}
New-MgEntitlementManagementAssignmentPolicy -BodyParameter $paramsNow I also cast the first element of "$choices" as an [ordered] hashtable:
$accessPackageId = "aca61375-7c6c-4842-910f-1bba4bc7e894"
$localizations = @(
@{
text = "France"
languageCode = "en-US"
}
)
$choices = @(
[ordered]@{
"@odata.type" = "#microsoft.graph.accessPackageAnswerChoice"
text = "France"
actualValue = "FR"
localizations = $localizations
}
)
$questions = @(
[ordered]@{
"@odata.type" = "#microsoft.graph.accessPackageMultipleChoiceQuestion"
sequence = "1"
isRequired = "true"
isAnswerEditable = "true"
text = "What country are you working from?"
isMultipleSelectionAllowed = "false"
choices = $choices
}
)
$params = @{
accessPackage = @{
id = $accessPackageId
}
displayName = "A Policy With Questions"
description = ""
allowedTargetScope = "allMemberUsers"
expiration = @{
type = "afterDuration"
endDateTime = $null
duration = "P90D"
}
requestorSettings = @{
enableTargetsToSelfAddAccess = $true
enableTargetsToSelfUpdateAccess = $true
enableTargetsToSelfRemoveAccess = $true
allowCustomAssignmentSchedule = $true
}
requestApprovalSettings = @{
isApprovalRequiredForAdd = $false
isApprovalRequiredForUpdate = $false
}
questions = $questions
}
New-MgEntitlementManagementAssignmentPolicy -BodyParameter $paramsWhich throws: Property choices in payload has a value that does not match schema.
The same error is thrown when the elements of "localizations" are cast to [ordered]. It seems the questions section can deal with ordered hashtables just fine but its subelements don't. There might be too strict type checking happening somewhere rejecting the ordered hashtable?
TLDR: You cannot use output from ConvertFrom-Json -AsHashtable directly as some underlying type checking is preventing use of ordered hashtables.
Note: Not sure if this problem is only limited to New-MgEntitlementManagementAssignmentPolicy or more cmdlets. This may will lead many on a merry chase.