Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove all users from all ou's

Posted on 2016-09-01
4
Medium Priority
?
33 Views
Last Modified: 2016-09-01
I have a home lab and testing some scripts.  How can I delete all users from all OU's and ou's within ou's?  I can delete all users in an ou with this. But within that OU I have about 10 different ou's and I have about 20 ou, with 10 different ou's within each.

Get-ADUser -Filter * -SearchBase "OU=Students,OU=Peabody,DC=homelab,DC=COM" | Remove-ADUser
0
Comment
Question by:Roccat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Roccat
ID: 41780733
it looks like this works

Get-ADUser -Filter * | Remove-ADUser
0
 
LVL 40

Accepted Solution

by:
Subsun earned 1000 total points
ID: 41780751
Users OU contains default accounts.. Following command will give you all users except default Users OU, you can pipe it to  Remove-ADUser
Get-ADUser -Filter * |?{$_.distinguishedname -notmatch "CN=Users"}

Open in new window

0
 
LVL 41

Assisted Solution

by:footech
footech earned 1000 total points
ID: 41780754
Your original command will remove all users within the "OU=Students,OU=Peabody,DC=homelab,DC=COM" OU and any child OUs.  Only if you changed the -searchscope parameter to 'OneLevel' would it not find users in child OUs.
0
 

Author Closing Comment

by:Roccat
ID: 41780812
Thanks !
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question