Solved

remove all users from all ou's

Posted on 2016-09-01
4
24 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
  • 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 250 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 39

Assisted Solution

by:footech
footech earned 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now