You need to add two entries to the ACL for the object:
I just dug up some really old code to do this that should work:
Dim currentOU as DirectoryEntry ' This is the object you want to protect
Dim deleteAce As New ActiveDirectoryAccessRule(New NTAccount("Everyone"), ActiveDirectoryRights.Delete, AccessControlType.Deny)
Dim deleteSubtreeAce As New ActiveDirectoryAccessRule(New NTAccount("Everyone"), ActiveDirectoryRights.DeleteTree, AccessControlType.Deny)
Dim currentACL As ActiveDirectorySecurity = currentOU.ObjectSecurity
Dim deleteDeny As Boolean = False
Dim deleteSubtreeDeny As Boolean = False
For Each ace As ActiveDirectoryAccessRule In currentACL.GetAccessRules(True, False, GetType(NTAccount))
If ace.IdentityReference.Value = "Everyone" Then
If ace.ActiveDirectoryRights = ActiveDirectoryRights.Delete Then
deleteDeny = True
ElseIf ace.ActiveDirectoryRights = ActiveDirectoryRights.DeleteTree Then
deleteSubtreeDeny = True
End If
End If
Next
If Not (deleteDeny AndAlso deleteSubtreeDeny) Then
currentACL.AddAccessRule(deleteAce)
currentACL.AddAccessRule(deleteSubtreeAce)
currentOU.CommitChanges()
Console.WriteLine("Protected: " & currentOU.Path)
End If
You just have to tell to show that property with the Get-ADObject parameter:-Properties
Get-ADobject -Server "myservername+fqdn" `
-Filter {objectclass -eq "mydominzone"} `
-SearchBase "DC=DomainDNSZones,DC=aa,DC=bb,DC=cc" `
-Properties ProtectedFromAccidentalDeletion
Interestingly, there isn't actually any flag in Active Directory for that. All it does is add a "deny delete" permission for "Everyone" to the account. But both and Set-ADObject translate that into a property that you can set and read. And even AD Users and Computers shows it as a checkbox.Get-ADObject