When creating an OU in AD, ticking the Protect from Accidental Deletion box seems like a good idea. Until you go to delete the OU. Even more so if you have multiple nested OUs and just want to delete the top level one.

Powershell to the rescue! We can use Get-ADOrganizationalUnit (note US spelling) to select all the OUs within a supplied OU and then use Set-ADObject and ProtectedFromAccidentalDeletion

Get-ADOrganizationalUnit -SearchBase "OU=NameOfOU,DC=ogs,DC=internal" -Filter * | ForEach-Object {

    Set-ADObject -Identity $_ -ProtectedFromAccidentalDeletion:$false


Once run, the top level OU can be deleted, removing all the sub OUs as well.


Leave a Reply

Avatar placeholder

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.