How to assign all users to a compliance policy

Alexander Hamre 0 Reputation points
2023-10-13T07:00:49.4866667+00:00

Im trying to assign the "all users" group in graph explorer but get this error:

{
    "error": {
        "code": "BadRequest",
        "message": "Unsupported @odata.type value: please do not provide a metadata document URI.",
        "innerError": {
            "date": "2023-10-13T06:40:35",
            "request-id": "373b91f0-3fb7-4235-aeff-94512a78575b",
            "client-request-id": "31b53b35-fc2c-e029-79a6-cec1ff6bc44f"
        }
    }
}

This is the url:

https://graph.microsoft.com/beta/deviceManagement/deviceCompliancePolicies/{deviceCompliancePolicy-id}/assignments/

This is the body:

{
    "@odata.type": "#microsoft.graph.deviceCompliancePolicyAssignment",
    "target": {
        "@odata.type": "microsoft.graph.#microsoft.graph.allLicensedUsersAssignmentTarget",
        "deviceAndAppManagementAssignmentFilterId": null,
        "deviceAndAppManagementAssignmentFilterType": "none"
    },
    "source": "direct",
    "sourceId": "{deviceCompliancePolicy-id}"
}
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,839 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alexander Hamre 0 Reputation points
    2023-10-27T10:42:05.1233333+00:00

    I figured it out.

    $uri = "https://graph.microsoft.com/v1.0/deviceManagement/deviceCompliancePolicies/$($DefaultCompliancePolicy.Id)/assign"
    $json = '
    {
        "assignments": [
            {
                "target": {
                    "@odata.type": "#microsoft.graph.allLicensedUsersAssignmentTarget"
                }
            }
        ]
    }
    '
    
    Invoke-MgGraphRequest -Uri $uri -Method POST -Body $json
    
    0 comments No comments