April 24, 2014

Exchange 2010 - distribution lists clean up

Run in Exchange Management Shell:

$DL= get-distributiongroup -resultsize unlimited
$DL |? {!(get-distributiongroupmember $_)} | select Name,DisplayName,Alias,PrimarySmtpAddress,DistinguishedName | export-csv EmptyGroups.csv

Import module for Active Directory:
Import-Module ActiveDirectory

Move AD groups to dedicated OU (for organizational perspective):
Import-Csv EmptyGroups.csv | foreach {move-ADObject -Identity $_.DistinguishedName -TargetPath "OU=ExampleOU,DC=example,DC=local"}

Distribution groups could be disabled in 2 ways:
1. Navigate to Recipient Configuration - Distibution Group and sort groups by Organizational Unit, select multiple groups and click disable.
2. Run following PowerShell script: Import-Csv EmptyGroups.csv | foreach {Disable-DistributionGroup -Identity $_.Alias}

No comments:

Post a Comment