Hi Mytoast Admin,
Thanks for reaching out.
You can use Json batching mentioned at the link https://learn.microsoft.com/en-us/graph/json-batching which is the concept of combining multiple Graph request into one and make a batch call. One such example is shown below to add multiple users.
POST https://graph.microsoft.com/v1.0/$batch
{
"requests": [{
"id": "1",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "allentest01",
"mailNickname": "allentest01",
"userPrincipalName": "allentest01@{tenant}.onmicrosoft.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": true,
"password": "{password-value}"
}
},
"headers": {
"Content-Type": "application/json"
}
}, {
"id": "2",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "allentest02",
"mailNickname": "allentest02",
"userPrincipalName": "allentest02@{tenant}.onmicrosoft.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": true,
"password": "{password-value}"
}
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
Based upon this link : https://learn.microsoft.com/en-us/graph/json-batching#batch-size-limitations JSON batch requests are currently limited to 20 individual requests.
In similar way you can you use this for creating groups. https://learn.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=http
and for creating multiple groups at a time, you can also use JSON batching of Graph as mentioned above.
To Add and remove multiple users to a group in once.
There is not an endpoint which we can use to remove users from AAD Group in batch. But there is a batch endpoint which combines multiple requests in one HTTP call. It also have a limitation of 20. So we can't delete too many users in one call.
Working C# example is below. Please comment if following is required in PowerShell.
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var additionalData = new Dictionary<string, object>()
{
{"******@odata.bind", new List<string>()}
};
(additionalData["******@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/users/{id}""); // first user id
(additionalData["******@odata.bind"] as List<string>).Add("https://graph.microsoft.com/v1.0/users/{id}""); // second user id
var group = new Group
{
AdditionalData = additionalData
};
await graphClient.Groups["{group-id}"]
.Request()
.UpdateAsync(group);
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".