Freshly posted for you on TNWiki: Active Directory PowerShell: List items with “Protect object from accidental deletion” setting
Ever got in a situation where you as AD domain admin were blocked from deleting items?
Or did you ever receive an “Access denied” when you tried to delete items from AD, even with full admin rights?
Then you better check if AD has the “protect from accidental deletion” activated on the object, container or OU…
In case you want to check a larger collection of items for this setting, it quickly becomes complicated.
This article helps you to get an overview by using Powershell, and an export of the impacted items to a CSV file.
As explained by : James ONeill (Windows Server 2008 Protection from Accidental Deletion)
“The functionality to prevent accidental deletion is not based on a new attribute in Active Directory. It is enabled by ticking a check box on the Object tab of the particular object you wish to protect. The Object tab is only visible when the Advanced Features option is selected from the View menu of Active Directory Users and Computers. When the tick box is checked the permissions on the object are changed. A “Deny” permission is created which stops deletion of the object. “
This script finds all AD objects protected from accidental deletions.
This script uses logic that has been developed by:
- Ashley McGlone,
Microsoft Premier Field Engineer, March 2013,
- Source: https://gallery.technet.microsoft.com/Active-Directory-OU-1d09f989
- Ashley McGlone, March 25, 2013
- abizer_hazratJune 9, 2009
- James ONeill, October 31, 2007
This script only runs if you can load the AD PS module eg. run the analysis
on a DC.
- List Protect object from accidental deletion setting in AD (full version)
- List Protect object from accidental deletion setting in AD (light version)
Full Version (with progress bar)
Light version (without progress bar)
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that You agree:
(i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded;
(ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and
(iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.
This posting is provided “AS IS” with no warranties, and confers no rights.
(Latest update: 2020-12-31)