Accidental deletion of organizational unit's

Do not delete security..

In this article I'll explain how to find Organizational Units on with the accidental deletion is not set. With this command you find every OU that is not protected.

Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false}

When OU exists that are not protected you can protect every OU with this Cmdlet.

Get-ADOrganizationalUnit -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $false} | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true


If you want to protect only OU's from a OU dwn to the end of this OU you can do it like this.

Get-OrganizationalUnit -SearchText "Hamburg" | where {$_.ProtectedFromAccidentalDeletion -eq $false} | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true


If you want to remove the flag from a tree of OU's you can do it like this.

Get-OrganizationalUnit -SearchText "Hamburg" | where {$_.ProtectedFromAccidentalDeletion -eq $false} | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $false

Written by Arne Tiedemann on Wednesday May 4, 2016
Permalink - Tags: Powershell, Active, Directory, Security

« New disk - Core prompt »