July 2017
Intermediate to advanced
648 pages
31h 9m
English
To remove disabled Active Directory user accounts from all distribution groups in the organization, use the following code:
$groups = Get-DistributionGroup -ResultSize Unlimited
foreach($group in $groups){
Get-DistributionGroupMember $group |
?{$_.RecipientTypeDetails -like '*User*'} |
Get-User | ?{$_.UserAccountControl -match 'AccountDisabled'} |
Remove-DistributionGroupMember $group -Confirm:$false
}
Read now
Unlock full access