- 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 the Organizational Unit (OU) from the active directory using PowerShell?
To delete the OU from the Active Directory using PowerShell, we need to use the command Remove-ADOrganizationUnit
Remove-ADOrganizationalUnit -Identity "OU=LabUsers,DC=Labdomain,DC=Local"
If the OU is protected from the accidental delete, you will receive an Access is Denied error as shown below.
Remove-ADOrganizationalUnit : Access is denied At line:1 char:1 + Remove-ADOrganizationalUnit -Identity "OU=LabUsers,DC=Labdomain,DC=Lo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (OU=LabUsers,DC=Labdomain,DC=Local:ADOrganizationalUnit) [Remove-ADOrgan izationalUnit], UnauthorizedAccessException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.UnauthorizedAccessException,Microsoft.ActiveDirectory.Managem ent.Commands.RemoveADOrganizationalUnit
So for that, first you need to disable the protected mode using the Set-ADOrganizationalUnit command and then need to run the remove command as shown below.
$ou = "OU=LabUsers,DC=Labdomain,DC=Local" Set-ADOrganizationalUnit -Identity $ou -ProtectedFromAccidentalDeletion $false Remove-ADOrganizationalUnit -Identity $ou -Confirm:$false -Verbose
You need to make sure that there are no child objects that exist otherwise, OU won’t get deleted.
Advertisements