Distribution group membership audit
Documentation: Microsoft Learn
The outer enumeration returns every distribution group, and for each one Get-DistributionGroupMember lists its members with its own unlimited result size.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-DistributionGroup -ResultSize Unlimited | ForEach-Object { Get-DistributionGroupMember $_ -ResultSize Unlimited | Select-Object @{ Name = "Group"; Expression = { $_.Name} },Name,PrimarySmtpAddress }- Stage 1Get-DistributionGroup
-ResultSize - Stage 2ForEach-Object
Positional values or no named parameters
How it works
The outer enumeration returns every distribution group, and for each one Get-DistributionGroupMember lists its members with its own unlimited result size. A calculated property named Group is meant to label each member row with the group it came from.
Adapting it
Capture the group object into a loop variable before the inner pipeline runs and reference that variable inside the calculated property, which is what makes the label point at the right thing.
Requirements
ExchangeOnlineManagement module with a Connect-ExchangeOnline session.
If the result is unexpected
A distribution-group membership export differs from mail-delivery expectations.
Nested and dynamic membership behave differently from a direct static member list.
- Identify the group type and compare direct members with the membership model used for delivery.
Validate the result
The export labels direct static membership and does not claim dynamic evaluation where none occurred.
Keep the check reliable
Document whether nested groups or dynamic recipient filters are part of the review.