PowerShell | Accidental Deletion AD OU

          Get list of OU from Searchbase
          Get OU's where Protect from Deletion is enabled

          Display OU's out to screen

          Change accidental deletion setting 
Author:   Scott Head
Date:     05/09/2022
Version:  1.0 


# Path to search in for OU's
$searchbase = 'OU=Domain Devices,DC=YourDomain,DC=net'

# Get all the OU's that are protected
$protectedOrganizationalUnits = Get-ADOrganizationalUnit -searchbase $searchbase -filter * -Properties ProtectedFromAccidentalDeletion | where {$_.ProtectedFromAccidentalDeletion -eq $true}

# Display OU's that are protected
$protectedOrganizationalUnits | Select DistinguishedName, ProtectedFromAccidentalDeletion, Name

# Disable protection
$protectedOrganizationalUnits | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $false