Last active
April 11, 2024 13:08
-
-
Save dreadsend/27a0c82e1b643d8ae603bbc5720865c7 to your computer and use it in GitHub Desktop.
Readable Graph API Batch Requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $results = [System.Collections.Generic.List[Object]]::new() | |
| # Batches Currently have a max Request Amount of 20 | |
| for ($i = 0; $i -lt $users.Count; $i += 20) { | |
| $batchObjects = $users[$i..($i + 19)] | |
| $batch = @{} | |
| $batch['requests'] = [System.Collections.Generic.List[Object]]::new() | |
| $number = 0 | |
| foreach ($id in $batchObjects.id){ | |
| $batch['requests'].Add(@{ | |
| id = $number + $i | |
| method = "GET" | |
| url = "/users/$id/licenseDetails" | |
| }) | |
| $number++ | |
| } | |
| $response = Invoke-MgGraphRequest -Method POST -URI 'https://graph.microsoft.com/v1.0/$batch' -body $batch -OutputType PSObject | |
| $results.AddRange($response.responses.body) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment