- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete all users from specific OU using PowerShell?
To remove all users from the specific OU, we need to first retrieve the users from that OU. For example, we have 3 users in the OU called LABDOMAIN and we need to delete them all.
Get-ADUser -SearchBase "OU=LabUsers,DC=labdomain,DC=local" -Filter *
The above command will retrieve users from the specific OU and then we can use the Remove-ADUser command to delete them all.
Example
Get-ADUser -SearchBase "OU=LabUsers,DC=labdomain,DC=local" -Filter * | Remove-ADUser -Confirm:$false -Verbose
-Confirm switch has been added to bypass the confirmation for all the users. The default confirmation is true.
Output
VERBOSE: Performing the operation "Remove" on target "CN=JensonA,OU=LabUsers,DC=labdomain,DC=local". VERBOSE: Performing the operation "Remove" on target "CN=ChrisT,OU=LabUsers,DC=labdomain,DC=local". VERBOSE: Performing the operation "Remove" on target "CN=ChiragN,OU=LabUsers,DC=labdomain,DC=local".
Advertisements