Skip to content

Instantly share code, notes, and snippets.

@dreadsend
Last active April 11, 2024 13:08
Show Gist options
  • Select an option

  • Save dreadsend/27a0c82e1b643d8ae603bbc5720865c7 to your computer and use it in GitHub Desktop.

Select an option

Save dreadsend/27a0c82e1b643d8ae603bbc5720865c7 to your computer and use it in GitHub Desktop.
Readable Graph API Batch Requests
$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