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 2: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 6:07am

works perfectly - Thanks!!!
June 17th, 2010 8:44am

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 3: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 3: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
June 30th, 2010 8:31pm

Here is a powershell function that removes user memberships from all security and distribution groups (except of course Domain Users group): ************************************************************************** $users= get-aduser -Filter * -SearchBase "ou=ExEmployees,dc=contoso,dc=com" Function RemoveMemberships { param([string]$SAMAccountName) $user = Get-ADUser $SAMAccountName -properties memberof $userGroups = $user.memberof $userGroups | %{get-adgroup $_ | Remove-ADGroupMember -confirm:$false -member $SAMAccountName} $userGroups = $null } $users | %{RemoveMemberships $_.SAMAccountName} *************************************************************************** Hope that someone will find this helpful! Cheers!
October 4th, 2011 3:53am

Laiq - works like a champ.Where Technology Meets Talent
Free Windows Admin Tool Kit Click here and download it now
November 3rd, 2011 11:50am

Perfect, just the script I was after. Very helpful
July 16th, 2012 11:49pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics