'Microsoft-Graph: Invoke-MgGraphRequest returns unable to cast object of type JsonObject to JsonArray
I am trying to use Invoke-MgGraphRequest to convert immutableEntryIds to ewsIDs. I have been following Microsoft's documentation and have created the following PowerShell script:
Import-Module Microsoft.Graph.Users.Actions
$params = @{
InputIds = @(
"{<my immutable EntryID 1>}",
"{<my immutable EntryID 2>}"
)
SourceIdType = "immutableEntryId"
TargetIdType = "ewsId"
}
Invoke-MgTranslateUserExchangeId -UserId $userId -BodyParameter $params
Running this script results in the following error:
Invoke-MgTranslateUserExchangeId : Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'.
At line:1 char:1
+ Invoke-MgTranslateUserExchangeId -UserId $userId -BodyParameter $para ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-MgTransl...geId_Translate1], InvalidCastException
+ FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.InvokeMgTranslateUserExchangeId_Translate1
I have seen similar errors for other MgGraph commands that are open issues on Github. Has anyone been able to get the Invoke-MgTranslateUserExchangeId command without this error occuring?
Solution 1:[1]
I get the same issue with Invoke-MgTranslateUserExchangeId but you should be able to work around it using Invoke-MgGraphRequest eg
Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/me/translateExchangeIds" -Body $params -Method POST
Its bug in PowerShell module something to do with the way their auto generation code works so you might want to create a issue in gitHub.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Glen Scales |
