?
Solved

remove all users from all ou's

Posted on 2016-09-01
4
Medium Priority
?
32 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 40

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A brief introduction to what I consider to be the best editor for PowerShell.
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

800 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