microsoft / mggraph-intune-samples

Repository to hold Microsoft Intune script samples for the Microsoft Graph PowerShell SDK
https://learn.microsoft.com/en-us/graph/api/resources/intune-graph-overview
MIT License
131 stars 30 forks source link

New-mgDeviceManagementDeviceCompliancePolicy_Create Cannot create an abstract class #12

Closed stevejmonk closed 3 months ago

stevejmonk commented 3 months ago

I'm importing a fully formed JSON, exported from another tenant, it looks like the request being sent by this command is truncating the input JSON, in the request body there appears to be multiple missing fields and values

[https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies]

Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.19045; en-US),PowerShell/2024.2.2 Accept-Encoding : gzip SdkVersion : graph-powershell-beta/2.19.0 client-request-id : cc1f5074-d62a-4378-a733-653c8b5c8146

Body:

"AdditionalProperties": { "@odata.context": [https://graph.microsoft.com/v1.0/$metadata#deviceManagement/deviceCompliancePolicies(id,displayName,description,scheduledActionsForRule())/$entity] "@odata.type": "#microsoft.graph.iosCompliancePolicy", scheduledActionsForRule@odata.context: [https://graph.microsoft.com/v1.0/$metadata#deviceManagement/deviceCompliancePolicies(guid)/microsoft.graph.iosCompliancePolicy/scheduledActionsForRule]() }, "description": "Compliance Policy for Corporate iOS devices", "displayName": "Import-test-MDM-comp", "scheduledActionsForRule": [ { "id": "5517726c-e0e8-4afc-9087-0380ea6bbc97" } ] }

DEBUG: ============================ HTTP RESPONSE ============================

Status Code: BadRequest

Headers: Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 7e0df90c-e8ec-4bb4-85a1-f0f004f21e09 client-request-id : cc1f5074-d62a-4378-a733-653c8b5c8146 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"UK South","Slice":"E","Ring":"5","ScaleUnit":"003","RoleInstance":"LO2PEPF00003336"}} Date : Thu, 01 Aug 2024 11:12:27 GMT

Body: { "error": { "code": "ModelValidationFailure", "message": "Cannot create an abstract class.", "innerError": { "message": "Cannot create an abstract class.", "date": "2024-08-01T11:12:27", "request-id": "7e0df90c-e8ec-4bb4-85a1-f0f004f21e09", "client-request-id": "cc1f5074-d62a-4378-a733-653c8b5c8146" } } }

Mahopper commented 3 months ago

Hi @stevejmonk, issues for the Graph PowerShell SDK itself should be filed in this repository: https://github.com/microsoftgraph/msgraph-sdk-powershell

If this is not an issue with one of the sample scripts, but the Graph PowerShell SDK itself, please file an issue there. Going to close this for now, but please let me know if I misunderstood and it can be re-opened.

It also may be worth looking at wrapping your GET request with .ToJsonString() from the initial tenant. For example: (Get-mgDeviceManagementDeviceCompliancePolicy -DeviceCompliancePolicyId "FOO").ToJsonString()

Will return the raw JSON response, which may be easier to work with for policy import/export depending on your scenario rather than manipulating a complex object.