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?
2 Answers
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.
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.
I totally agree! Fetching millions of records just to drop most of them seems wasteful. Better to filter earlier.
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?

That was it, thank you!