Reputation: 1
I have a call to MS Graph that works perfectly... we're trying to pull a report and export it. Everything works fine, but when we put it into PROD we have 17k users to evaluate which likely will take 3-4 hours to run. Problem is after about 1/2 way (seems to be different timeout each time). It is working perfectly until this, so it seems to be a timeout or throttling of some soft. The error I get is Error 401 Unauthorized and it refuses to move onto the next use see below.
Invoke-WebRequest : The remote server returned an error: (401) Unauthorized. At C:\temp\GatherAzureUsers.ps1:98 char:18
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ConvertFrom-JSon : Invalid JSON primitive: . At C:\temp\GatherAzureUsers.ps1:99 char:32
~~~~~~~~~~~~~~~~
I've tried to simply re-authenticate periodically throughout the large while loop. I've tried to force a disconnect (Disconnect-MgGraph) and reconnect. For the connect and reconnect we've tried using an app secret as well as simple, manual authentication using the regular browser. Still has the same issue.
Note I'm likely processing 7000 - 10,000 users before it starts timing out (over a 1.5 - 2 hour period). So I don't think I'm hitting a limit for time as I've read in a few places it will have a 100ms timeout or 100 items (as examples of some of the limits I was able to find).
I have looked at setting the overall timeout below, but thats not working in my PowerShell command (it throws an error The term 'graphServiceClient.HttpProvider.OverallTimeout' is not recognized as the name of a cmdlet...) graphServiceClient.HttpProvider.OverallTimeout = TimeSpan.FromHours(6);
Upvotes: 0
Views: 533
Reputation: 11
I have the same issue, there are two errors we gett; 401 for disconnection and 429 for throttling issues.
Used this to check for connectivity instead of disconnect/reconnect:
$context = Get-MgContext
if (-not $context) {
write-host -ForegroundColor yellow "Connecting Graph"
Connect-MgGraph -ClientId $ClientID -TenantId $TenantID -Certificate $ClientCertificate -NoWelcome
} else {
write-host -ForegroundColor yellow "Graph already connected"
}
}
Used this to help throttle the requests when in a loop:
#Anti-throttling control
Start-Sleep -Milliseconds 300
I think they are related issues where the backend SP server is kicking out connections when large numbers of requests are not managed.
Upvotes: 1