Powershell-Script to remove all group memberships for one user
Hi there,
ive searched all over, but found nothing out there. So i hope you can help me in this:
I have to create a powershell-command which deletes all group-membershipments for one user. But only the mail-enabled groups.
I dont have an idea :( you ? :-)
June 17th, 2010 9:17am
Hi there,
ive searched all over, but found nothing out there. So i hope you can help me in this:
I have to create a powershell-command which deletes all group-membershipments for one user. But only the mail-enabled groups.
I dont have an idea :( you ? :-)
You can use this script
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
$DGs= Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "user@domain.com"
}
foreach( $dg in $DGs){
Remove-DistributionGroupMember $dg -Member user@domain.com
}
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.
Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
Free Windows Admin Tool Kit Click here and download it now
June 17th, 2010 1:07pm
works perfectly - Thanks!!!
June 17th, 2010 3:44pm
That's great!
Thank you for your sharing!
Your expertise never fails to impress!
Free Windows Admin Tool Kit Click here and download it now
June 18th, 2010 10:05am
Hi,
You are welcome.
My pleaseure to work with exchange :)
Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
June 18th, 2010 10:47am
Might some similar script be used to remove a user from all security groups except the primary (e.g., domain users)?
Free Windows Admin Tool Kit Click here and download it now
July 1st, 2010 3:31am