Exchange remove member from all e-mail groups using shell

Remove-DistributionGroupMember  -member jon.doe -confirm:$false -Identity “Staff”

Staff = group name

Add-DistributionGroupMember for adding members to a group

To remove jon.doe from all groups:

$GG = Get-DistributionGroup

$RG = $GG  | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains “jon.doe@domain.com”}

foreach( $dg in $RG ){
Remove-DistributionGroupMember $dg -Member jon.doe@domain.com
}

Script:

Create a ps1 file:

email = (read-host “email”)

$GG = Get-DistributionGroup
$RG = $GG  | where {(Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains “$email”}

foreach( $dg in $RG ){
Remove-DistributionGroupMember $dg -Member $email
}

Get-Mailbox -Identity $email | Set-Mailbox -HiddenFromAddressListsEnabled $true  ( hide address from GAL )

This entry was posted in Exchange and tagged . Bookmark the permalink.

One Response to Exchange remove member from all e-mail groups using shell

  1. obviously like your web-site but you have to take a look at the spelling on quite a
    few of your posts. Many of them are rife with spelling issues and
    I to find it very bothersome to tell the reality nevertheless I’ll definitely come back again.

Leave a Reply

Your email address will not be published. Required fields are marked *