Why is ResultSize Unlimited Not Working for Distribution Groups in Exchange Online?
Asked by
hash+salt42
I'm trying to run a PowerShell command to find all distribution groups that a specific user is a member of: `Get-DistributionGroup -ResultSize Unlimited | Where-Object { (Get-DistributionGroupMember $_.Name | Select-Object -ExpandProperty PrimarySmtpAddress) -contains $userEmail }`. However, I'm getting a warning that there are more results available than displayed, indicating I should increase the ResultSize parameter. Can anyone suggest why this is happening or offer a more efficient method to retrieve all the distribution groups for a user?
Answers
You could also tackle this from the opposite direction. Instead of fetching all distribution groups, get all memberships for the user first. Look for their memberships using commands like `Get-EntraUserMembership` or `Get-ADPrincipalGroupMembership`. That way, you shouldn't run into the same issue with ResultSize.
Reply to this answer
It sounds like the warning might be coming from the `Get-DistributionGroupMember` part of your command. Try adding the `-ResultSize` parameter there too; that usually helps get around the limitation.
hash+salt42: That was it, thank you!
Reply to this answer
Add your answer
Answers are reviewed before publication.
sundried: I totally agree! Fetching millions of records just to drop most of them seems wasteful. Better to filter earlier.
hash+salt42: We just migrated everything to 365 and don't have any Entra groups set up yet, though. Are you saying manually recreating them in Exchange Online also creates Entra groups?