Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added throttle handing for users pull #11

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added throttle handing for users pull
  • Loading branch information
NinjaStyle82 committed Oct 24, 2023
commit 7ce4a5950551fc24459ba5ddf8963e8fba912354
13 changes: 10 additions & 3 deletions GraphRunner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,15 @@ Function Get-AzureADUsers{
$usersEndpoint = "https://graph.microsoft.com/v1.0/users"
$userlist = @()
do{
$request = Invoke-WebRequest -Method GET -Uri $usersEndpoint -Headers @{"Authorization" = "Bearer $access_token"}
$out = $request.Content | ConvertFrom-Json
try{
$request = Invoke-WebRequest -Method GET -Uri $usersEndpoint -Headers @{"Authorization" = "Bearer $access_token"}
}catch {
if($_.Exception.Response.StatusCode.value__ -match "429"){
Write-Host -ForegroundColor red "[*] Being throttled... sleeping 5 seconds"
Start-Sleep -Seconds 5
}
}
$out = $request.Content | ConvertFrom-Json
$userlist += $out.value.userPrincipalName
if ($out.'@odata.nextLink') {
if(!$GraphRun){
Expand Down Expand Up @@ -5628,4 +5635,4 @@ Get-UserObjectID`t`t-`t Retrieves an object ID for a user
Write-Host -ForegroundColor green ("=" * 80)
Write-Host -ForegroundColor green '[*] For help with individual modules run Get-Help <module name> -detailed'
Write-Host -ForegroundColor green '[*] Example: Get-Help Invoke-InjectOAuthApp -detailed'
}
}