Removing disabled user accounts from distribution groups
A standard practice among most organizations when users leave or have been let go is to disable their associated Active Directory user account. This allows an administrator to easily re-enable the account in the event that the user comes back to work, or if someone else needs access to the account. Obviously, this has become a common practice because the process of restoring a deleted Active Directory user account is a much more complex alternative. Additionally, if these user accounts are left mailbox-enabled, you can end up with distribution groups that contain multiple disabled user accounts. This recipe will show you how to remove these disabled accounts using the Exchange Management Shell.
How to do it...
To remove disabled Active Directory user accounts from all the distribution groups in the organization, use the following code:
$groups = Get-DistributionGroup -ResultSize Unlimited foreach($group in $groups){ Get-DistributionGroupMember...