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.


English
polski