Recently we got tasked with protecting all objects in a specific OU from accidental deletion. There were about 60 users in this OU so we wanted to script this and by scripting this we would also be able to set up a scheduled task so that the change got applied to new users who got added to the OU also.
First of all open PowerShell and run “Import-Module activedirectory”
Now run the following but obviously change the DN name so that it points at the OU relevant for your domain.
Get-ADobject -Filter * -SearchBase “OU=Users,DC=Domain,DC=com” | Set-adobject -ProtectedFromAccidentalDeletion $true
All users in the OU should now be protected from accidental deletion