Public/Protect-AllOUs.ps1
function Protect-AllOUs { <# .SYNOPSIS Set the "Protected from accidental deletion" flag on all OUs .DESCRIPTION Set the "Protected from accidental deletion" flag on all OUs .NOTES Author : Marc Bouchard - @subnet192 .DEPENDENCIES ActiveDirectory module required .INPUTS No inputs required .OUTPUTS None .EXAMPLE Protect-AllOUs #> <# ----------------------------------------------------------[Declarations]---------------------------------------------------------- #> $ADDomain = Get-ADDomain $searchbase = $ADDomain.DistinguishedName <# -----------------------------------------------------------[Execution]------------------------------------------------------------ #> Get-ADOrganizationalUnit -searchbase $searchbase -filter * -Properties ProtectedFromAccidentalDeletion | where { $_.ProtectedFromAccidentalDeletion -eq $false } | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true } #END function |