How do I assign an Windows Autopilot Deployment Profile to multiple groups using graph API?

Johan Berg 65 Reputation points
2023-06-01T11:37:04.6666667+00:00

To assign Windows Autopilot Deployment Profile to one group I use the following code.

Request Body:

{
    "target": {
        "@odata.type": "#microsoft.graph.groupAssignmentTarget",
        "groupId": "<The group id>"
    }
}

But how do I assign it to multiple groups? I have tested the following code (Based on ide from @Crystal-MSFT answer in an earlier question) but it don't work.

Request Body:

[
    {
        "target":  {
                       "@odata.type":  "#microsoft.graph.groupAssignmentTarget",
                       "groupId":  "<The group id>"
                   }
    },
    {
        "target":  {
                       "@odata.type":  "#microsoft.graph.groupAssignmentTarget",
                       "groupId":  "<The group id>"
                   }
    }
]

How do I assign it to multiple groups?

Br

Johan

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,540 questions
Microsoft Intune Configuration
Microsoft Intune Configuration
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Configuration: The process of arranging or setting up computer systems, hardware, or software.
1,712 questions
Microsoft Intune Enrollment
Microsoft Intune Enrollment
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Enrollment: The process of requesting, receiving, and installing a certificate.
1,243 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Johan Berg 65 Reputation points
    2023-07-28T09:46:11.03+00:00

    I managed to solve it in the following way:

    # Loop through the groupIds and assign the profile to each group
    foreach ($groupId in $groupIds) {
        $assignmentBody = @{
            target = @{
                "@odata.type" = "#microsoft.graph.groupAssignmentTarget"
                groupId = $groupId
            }
        } | ConvertTo-Json
    
        # Make the API call to assign the profile to the current group
    }
    
    
    1 person found this answer helpful.
    0 comments No comments