Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Export-M365DSCConfiguration hangs indefinitely on AAD components and never completes - WARNING: Throttling.....

Open artorro opened this issue 5 months ago • 8 comments


Module version: 1.26.603.1 PowerShell: 7.4 (pwsh) OS: Windows Server 2022 (GitHub Actions windows-latest) Auth method: OIDC (-AccessTokens)


What happens

When running Export-M365DSCConfiguration with components that include e.g. AADPIMGroupSetting, AADEntitlementManagementRoleAssignment, or AADAccessReviewDefinition, the export gets stuck on a single component and never continues in a larger tenant. The only output is a repeated warning:

WARNING: Throttling encountered, pausing and repeating request...

The warning repeats indefinitely at roughly 5-second intervals. After 40+ minutes on the same component, the process has to be killed manually or times out at the job level. No error is thrown and no export file.

artorro avatar Jun 30 '26 13:06 artorro

That's unfortunately an API rate limit that we hit with this resource. We're continually checking if any of the results are throttled and attempt to reload those instances. Because we're limited to ~20 requests per 10 seconds or something similar, a big tenant will take veeeery long to export.

FabienTschanz avatar Jun 30 '26 20:06 FabienTschanz

I found out that AADIdentityGovernanceProgram is hitting a deprecated endpoint. https://learn.microsoft.com/en-us/graph/api/resources/program?view=graph-rest-beta. So removing the component solves that problem (although it was disguised as a throttling issue). AADAccessReviewDefinition is the modern replacement. With the other components, I have manually created some guardrails so the retry doesn't come so often. This seem to help but I'm still experimenting. Was hoping that there was a more standard solution but I guess not. Thanks for your prompt reply.

artorro avatar Jun 30 '26 21:06 artorro

What are the guardrails you are experimenting with? Maybe we can adopt them in the project to improve throttling handling. We‘re always looking for improvements, if you could share your approach, we‘ll certainly consider it for implementation. Thank you!

FabienTschanz avatar Jun 30 '26 21:06 FabienTschanz

I am simply dividing the export-config into smaller chunks and then add a sleep timer between each. It works for all the components in my scope except 1. AADPIMGroupSetting goes to throttling immediately, without exporting a single item! I have even removed all other components but it didn't help.

The entire function should probably be redesigned because the issue is inside it and nothing I can wrap around.

artorro avatar Jul 02 '26 11:07 artorro

Okay, thank you. I'll investigate a bit further. There is something I want to try with a new library that's supposed to be even faster for large chunks of data and many requests with automatic throttling handling. I'll give that a try and keep you updated. But that will only be made available for PowerShell 7+, Windows PowerShell is not supported.

FabienTschanz avatar Jul 02 '26 11:07 FabienTschanz

Sounds good, before I'll let you go, I just found (perhaps) a bug with AADAccessReviewDefinition. I have extracted 85 instances but the last 2 gave me issues. It's most likely because there are warnings in Entra itself. The warning in Entra says: ([Triangle with exclamation mark] No access to review. Probably some ref. to a hard deleted object. However, in DSC it just fails to export with error message: An error occured while exporting resource {AADAccessReviewDefinition}: Response status code does not indicate success: BadRequest (Bad Request).

artorro avatar Jul 02 '26 13:07 artorro

@artorro I'll open a dedicated issue for that and ask for some information there. Regarding the throttling, I'm in the process of implementing PowerShell 7 with Mgx, a retry-aware Graph API client. Looks promising so far, certainly a bit faster, but even more reliable. However, I don't have a tenant with thousands of groups, just 150. AADPIMGroupSetting is a very difficult resource to handle because we can't see which groups have PIM enabled, so we need to query each and every group individually. If it takes too long, exclude it from your export.

FabienTschanz avatar Jul 03 '26 09:07 FabienTschanz

@artorro I'll be closing this issue here because we have some improvements coming in October with the next breaking change release. Thanks for mentioning the AADIdentityGovernanceProgram, we just deprecated the resource and will remove it in October as well. Any questions remaining regarding the throttling matter?

FabienTschanz avatar Jul 09 '26 21:07 FabienTschanz