All scripts
Microsoft 365 318
Export-DistributionGroupMembership
Exports every distribution group in the tenant along with its full member list to a single CSV, useful for an access review without clicking through each group in the admin center.
Export-DistributionGroupMembership.ps1
<#
.SYNOPSIS
Exports all distribution groups and their members to CSV.
.DESCRIPTION
Enumerates every distribution group in the tenant, resolves membership
for each one, and writes a flat CSV with one row per group/member pair
so the whole tenant's distribution list membership can be reviewed in
a spreadsheet instead of one group at a time in the admin center.
.PARAMETER ExportPath
Path to write the CSV to. Defaults to the current directory.
.EXAMPLE
.\Export-DistributionGroupMembership.ps1 -ExportPath C:\Reports
.NOTES
Requires ExchangeOnlineManagement and an active Connect-ExchangeOnline session.
.AUTHOR
Shehryar Hassan
#>
param(
[string]$ExportPath = (Get-Location).Path
)
$groups = Get-DistributionGroup -ResultSize Unlimited
$rows = foreach ($group in $groups) {
$members = Get-DistributionGroupMember -Identity $group.Identity -ResultSize Unlimited
if ($members) {
foreach ($member in $members) {
[pscustomobject]@{
GroupName = $group.DisplayName
GroupEmail = $group.PrimarySmtpAddress
MemberName = $member.DisplayName
MemberEmail = $member.PrimarySmtpAddress
}
}
} else {
[pscustomobject]@{
GroupName = $group.DisplayName
GroupEmail = $group.PrimarySmtpAddress
MemberName = "(empty group)"
MemberEmail = ""
}
}
}
$file = Join-Path $ExportPath "distribution-group-membership_$(Get-Date -Format yyyyMMdd_HHmmss).csv"
$rows | Export-Csv -Path $file -NoTypeInformation
Write-Host "Exported $($rows.Count) rows across $($groups.Count) groups to $file" -ForegroundColor Cyan
Read it before you run it, and test in a safe tenant first.