Skip to content

Instantly share code, notes, and snippets.

@RobinBeismann
Created January 15, 2021 20:56
Show Gist options
  • Save RobinBeismann/f3b0a88054caf43d8b2d839f27bf3258 to your computer and use it in GitHub Desktop.
Save RobinBeismann/f3b0a88054caf43d8b2d839f27bf3258 to your computer and use it in GitHub Desktop.
if($membersToAdd.Count -gt 0){
Write-Host("Writing membersToAdd")
$chunkArr = $membersToAdd
$chunks = [System.Collections.ArrayList]::new()
for ($i = 0; $i -lt $chunkArr.Count; $i += 20) {
if(($chunkArr.Count - $i) -gt 19) {
$null = $chunks.add($chunkArr[$i..($i + 19)])
}else{
$null = $chunks.add($chunkArr[$i..($chunkArr.Count - 1)])
}
}
Write-Host("membersToAdd: Split Members into $($chunks.count) as we can only push 20 per batch")
$count = 1
foreach ($chunk in $chunks) {
Write-Host("membersToAdd: Processing Chunk $count of $($chunks.Count)")
Invoke-WebRequest -UseBasicParsing -Uri "https://graph.microsoft.com/v1.0/groups/$backupGroupId" -Headers $Headers -Method Patch -ContentType 'application/json' -Body (@{
"[email protected]" = $chunk
} | ConvertTo-Json)
$count++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment