Get empty DL and delete them

Get empty DL delete them

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.

In the news
Load More