Solved

remove all users from all ou's

Posted on 2016-09-01
4
28 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

12 Experts available now in Live!

Get 1:1 Help Now