I'm writing a PowerShell script to set the ProtectFromAccidentalDeletion flag to "true" recursively on all OUs, objects, sub-OUs and their objects.
I need every object and "container of objects" within an OU protected against accidental deletion (and all that entails).
The script has a separate line for each OU, each sub-OU, each OU's objects, etc. It is quite long and I feel like I'm defeating the purpose of saving time by writing the script at all.
I use the following command for OUs:
Get-ADOrganizationalUnit -Filter * -SearchBase “ou=OU,ou=rootOU,dc=domain,dc=com” | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true
and this for objects:
Get-ADobject -Filter * -SearchBase “ou=OU,ou=rootOU,dc=aemea,dc=kao,dc=com” | Set-ADobject -ProtectedFromAccidentalDeletion $true
Those work fine for the specific OU or objects I'm targeting, but how can I set this value for every object and OU underneath the OU I target?
Thanks in advance for the advice and help, folks!