Created
July 22, 2015 15:19
-
-
Save alexinnes/da931a221378b6bcce46 to your computer and use it in GitHub Desktop.
Gets all users from a OU and removes them from their groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$users = get-aduser -filter * -SearchBase "OU=ToBeArchived,OU=Users,OU=PS,DC=ps,DC=internal" | select -Property samaccountname | |
$groups = get-aduser -filter * -SearchBase "OU=ToBeArchived,OU=Users,OU=PS,DC=ps,DC=internal" -Properties memberof | select -Property memberof -ExpandProperty memberof | |
foreach($user in $users){foreach($group in $groups){Remove-ADGroupMember $group -Members $user.samaccountname -whatif; $user}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment