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.


Leave a Comment

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

In the news
Load More