PowerShell Tip – How to remove AD OU and all child objects (another OUs, users, groups, computers)?

How to remove Active Directory Organizational Unit with all child objects (another OUs, users, groups, computers)? It is simple. The trick is to use Remove-ADObject -Recursive.

Get-ADOrganizationalUnit -Identity 'OU=ToDelete,DC=ad,DC=fabrikam,DC=com' |
    Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion:$false -PassThru |
    Remove-ADObject -Recursive -Confirm:$false

Leave a Reply

Your email address will not be published. Required fields are marked *