Disable Protect from Accidental Deletion from Active Directory OU With PowerShell

In this blog post, I will show you how to disable protect from accidental deletion from an organizational unit in AD using a PowerShell script.

The Protect from Accidental Deletion is a great feature. However, it can be a pain when you need to delete OU in a programmatic manner using PowerShell.

Since the delete OU PowerShell cmdlet doesn’t handle the feature there is a need to use a different cmdlet.

The Set-ADObject is the cmdlet that handles the feature.

In this script, a variable takes to OU that needs the feature disabled and using a for each loop it disables it.

One the option is disabled on the top OU; all the OUs can be deleted.


$delete = "ou=server,dc=test,dc=local" , "ou=Test-users,dc=test,dc=local"
foreach ($i in $delete)
Get-ADOrganizationalUnit $i | Set-ADObject -ProtectedFromAccidentalDeletion:$false -Verbose

Leave a Reply

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