powershell-intune-samples icon indicating copy to clipboard operation
powershell-intune-samples copied to clipboard

ManagedAppPolicy_Import_FromJSON.ps1 throws HTTP Bad request error

Open thutrang162 opened this issue 4 years ago • 5 comments

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 ManagedAppPolicy_Import_FromJSON.ps1:347 Zeichen:1

  • Add-ManagedAppPolicy -JSON $JSON_Output
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-ManagedAppPolicy
    
    
    

Please advise.

thutrang162 avatar Jan 18 '21 09:01 thutrang162

What type of policy are you importing? Android / iOS?

Can you share the JSON thats failing?

davefalkus avatar Jan 18 '21 09:01 davefalkus

It is a Windows policy. V3 - Windows - App protection policy.zip

thutrang162 avatar Jan 18 '21 10:01 thutrang162

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?

davefalkus avatar Jan 18 '21 18:01 davefalkus

Yes, right I had to modify it a little bit. Here is the script. Appprotectjson.zip

thutrang162 avatar Jan 19 '21 08:01 thutrang162

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 
    

thutrang162 avatar Feb 08 '21 15:02 thutrang162