Exchange 2010 remove disabled AD accounts from distribution groups

This post is also available in: Polish

When you need to find all disabled Active Directory accounts which belong to any distribution group, then you can use Exchange Management Shell and below command:

$groups = Get-DistributionGroup -ResultSize Unlimited
$report = foreach($group in $groups){
 Get-DistributionGroupMember $group |
 ?{$_.RecipientType -like '*User*' -and $_.ResourceType -eq $null} |
 Get-User | ?{$_.UserAccountControl -match 'AccountDisabled'} |
 Select-Object Name,RecipientType,@{n='Group';e={$group}}
}
$report | Export-CSV d:\scripts\disabled_group_members.csv -NoType

This command will return list of all disabled users with information about distribution group they belong. Out file is in CSV format so you can use it to remove users from group.

 

 

Print Friendly
Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>