Unused Distribution Groups

How to identify Inactive and Unused Distribution Groups in Microsoft 365 (Exchange Online)

I work for a company that has a large number of Distribution lists (around 1000 of them) and I know that half of them are not being used and have not been used for years. Like most companies, when staff leave you delete their email accounts but you likely don’t give much thought to the Distribution Lists. In this article I will show you how to Search Exchange Online for Distibution groups and –

  • Find Unused Distribution Groups
  • Find Empty Distribution Groups

How to Find Unused Distribution Groups

To do this, the best way is to use the Start-HistoricalSearch command.

Install the Exchange Online PowerShell (EXO) module and connect to your tenant:

Connect-ExchangeOnline

foreach ($group in Get-DistributionGroup)
{
Start-HistoricalSearch -ReportTitle $group.PrimarySmtpAddress -StartDate 01/01/2024 -EndDate 03/01/2024 -ReportType MessageTrace -RecipientAddress $group.PrimarySmtpAddress -NotifyAddress [email protected]
}


Note that this will only return a maximum of 250 distribution lists. So if you have more than 250 Distribution groups you will need to use some filtering to targeta group of Distribution groups.     In the example below i have filtered by a common them in the naming convention.
foreach ($group in Get-DistributionGroup Filter Where-Object {$_.Name -like "*DL*"})
{
Start-HistoricalSearch -ReportTitle $group.PrimarySmtpAddress -StartDate 01/01/2024 -EndDate 03/01/2024 -ReportType MessageTrace -RecipientAddress $group.PrimarySmtpAddress -NotifyAddress [email protected]
}

How to Find Empty Distribution Groups

Over time as users leave the organisation and if Distribution Groups are not managed correctly, they may end up with no users at all and become unpopulated. It is likely that an unpopulated Distribution group is no longer needed.

We can use Exchange PowerShell to find these empty Distribution Groups.

Connect-ExchangeOnline
$emptyGroups = foreach ($grp in Get-DistributionGroup -ResultSize Unlimited) {
if (@(Get-DistributionGroupMember –Identity $grp.DistinguishedName -ResultSize Unlimited).Count –eq 0 ) {
[PsCustomObject]@{
DisplayName = $grp.DisplayName
PrimarySMTPAddress = $grp.PrimarySMTPAddress
DistinguishedName = $grp.DistinguishedName
}
}
}
$emptyGroups | Export-Csv 'C:\Data\DLsToRemove.csv' -NoTypeInformation

Leave a Reply

Your email address will not be published. Required fields are marked *