Laeeq Qazi's Exchange Server Blog

Exchange Server blog

How to remove all group memberships for one exchange mailbox user

There is often a need to remove a mailbox user membership from all exchange distribution groups.

Here is a powershell script for this purpose.

e.g your user’s primary smtp address is user@domain.com, then this script will remove the membership of this user from each mail enabled exchange distribution groups:

########### Script Start #####################

$DGs= Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains “user@domain.com” }

foreach( $dg in $DGs){

Remove-DistributionGroupMember $dg -Member user@domain.com
}

########### Script End #####################

Note: Put above lines of code in a text file and save it as .ps1 file and then execute it in EMS or powershell console.

If you save this file in Exchange Scripts folder “C:\Program Files\Microsoft\Exchange Server\Scripts” OR “C:\Program Files\Microsoft\Exchange Server\V14\Scripts” then, in EMS, you will just need to enter the .ps1 file name and then press enter.
You might also need to set the powershell execution policy as RemoteSigned in EMS:

set-executionPolicy RemoteSigned

Regards,
Laeeq Qazi

Advertisements

June 18, 2010 - Posted by | Exchange 2007, Exchange 2010 |

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: