- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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".
- Related Articles
- How to delete the Organizational Unit (OU) from the active directory using PowerShell?
- How to delete the specific node from the XML file using PowerShell?
- How to delete all the file contents using PowerShell?
- How to delete the specific tag of Azure VM using PowerShell?
- How to delete all the tags of the azure resource using PowerShell?
- How to delete registry Key using PowerShell?
- How to create bulk users in the active directory using PowerShell?
- How to get connected remote desktop users on computers using PowerShell?
- How to delete the local group from the windows system using PowerShell?
- How to delete the windows certificate using PowerShell?
- How to delete registry key value (property) using PowerShell?
- How to delete empty files and folders using PowerShell?
- How to delete hidden files and folders using PowerShell?
- How to delete the Azure Resource Group using PowerShell?
- How to get the Azure images available from the specific publisher using PowerShell?

Advertisements