PowerShell : Remove all group memberships of every user in an OU

I'd like to have a powershell script that I can give a base OU and have the script walk through every user in that OU and remove the every group from each member in that OU. The end result would be that I would have an OU full of users which are a part of no security groups. Thank you in advance!

Who is Participating?
Jamie McKillopConnect With a Mentor IT ManagerCommented:

You need the free Quest cmdlets to run this script. This script will removed membership in all groups, including distribution groups. It is a little more complicated to exclude distribution groups but if you need to do that I can modify the script. You need to enter the OU in the format: 'OU=users,DC=domain,DC=com'

$OU = Read-Host "Enter OU:"
$Users = Get-QADUser -SizeLimit 0 -SearchRoot $OU
foreach ($user in $Users) {
	Remove-QADMemberOf -Identity $user.dn -RemoveAll

Open in new window

ssd-techAuthor Commented:
This was EXACTLY what I was looking for. Thank you!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.