Jump to content

Recommended Posts

Posted

Been looking around online but to no real look. I need to remove all group memberships (security groups) from quite a few users. They are now bunched together in an OU but need a simple way of removing group memberships.

 

Like always hoping for a GUI unless it is a simple powershell script!

Posted

This will remove all security groups from all users contained within a specified OU with the exception of the 'Domain Users' group. Be sure to test this on a few temp users before releasing it into the wild. :p

 

Import-Module ActiveDirectory
$users = Get-ADUser -SearchBase "OU=Students,OU=Users,DC=domain,DC=com" -Filter * 

foreach($user in $users){
 $groups = Get-ADPrincipalGroupMembership $user.SamAccountName | Where-Object {$_.name -NotLike '*Domain*'}
 foreach($group in $groups){
   
   Remove-ADGroupMember -Identity $group -Members $user

 }
}

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...