Get empty DL and delete them

Office365 PowerShell 3F7B65B7
Office365 PowerShell 3F7B65B7

How to get all distributions list on your organization which is empty using Powershell?

You have to use the following command:

Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember –identity $_.Name).Count –eq 0 } | select PrimarySmtpAddress | export-csv C:\EmptyDL.csv

By the way, this command also working for Office 365, before that you have to connect to the office 365.

How to remove the empty distribution list?

Import-csv C:\EmptyDL.csv | foreach {foreach {Remove-DistributionGroup $_.PrimarySmtpAddress}

You can use on “-Confirm” in order to skip about confirmation.


About Meir Peleg 338 Articles
My name is Meir Peleg, (Born 30/04/1991) live in ISRAEL. Live and breath IT world. Microsoft MVP Windows IT & VMware vExpert.