Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Removing disabled user accounts from distribution groups


A standard practice amongst 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 distribution groups in the organization, use the following code:

$groups = Get-DistributionGroup -ResultSize Unlimited

foreach($group in $groups){
 Get-DistributionGroupMember...