ManagedAppPolicy_Import_FromJSON.ps1 throws HTTP Bad request error
Since a couple of weeks I cannot import policies using the script anymore. The error I get is:
Response content:
{
"error": {
"code": "ModelValidationFailure",
"message": "Cannot create an abstract class.",
"innerError": {
"message": "Cannot create an abstract class.",
"date": "2021-01-18T09:19:03",
"request-id": "9875f246-1164-4339-8fcb-7a5b12659fc3",
"client-request-id": "9875f246-1164-4339-8fcb-7a5b12659fc3"
}
}
}
Add-ManagedAppPolicy : Request to https://graph.microsoft.com/Beta/deviceAppManagement/managedAppPolicies failed with HTTP
Status BadRequest Bad Request
In
- Add-ManagedAppPolicy -JSON $JSON_Output
-
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-ManagedAppPolicy
Please advise.
What type of policy are you importing? Android / iOS?
Can you share the JSON thats failing?
It is a Windows policy. V3 - Windows - App protection policy.zip
Thanks for details. Looking at the export sample script in this repository it doesn't export Window policies only iOS and Android:
https://github.com/microsoftgraph/powershell-intune-samples/blob/master/AppProtectionPolicy/ManagedAppPolicy_Export.ps1
Also the import sample uses the function Add-ManagedAppPolicy which is only for iOS and Android policies as the function used uses the following graph endpoint which won't import a Windows policy.
deviceAppManagement/managedAppPolicies
The Export / Import scripts haven't been updated in 3 years, could you share how you've got them to work?
Yes, right I had to modify it a little bit. Here is the script. Appprotectjson.zip
I get the same issue with: ManagedAppPolicy_Add.ps1 failed with this error, when I tried adding an exported WIP policy as JSON file:
Add-WindowsInformationProtectionPolicy : Request to https://graph.microsoft.com/Beta/deviceAppManagement/windowsInformationProtectionPolicies failed with HTTP Status InternalServerError Internal Server Error At line:895 char:1
- Add-WindowsInformationProtectionPolicy -JSON $ManagedAppPolicy_WIP
-
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-WindowsInformationProtectionPolicy