Greetings,
How can one query the AD database using powershell to only get you user objects with the ProtectedFromAccidentalDeletion property set to $True?
I tried using this one liner code with no success:
get-aduser -Filter * | where-object {$_.ProtectedFromAccidentalDeletion -eq $True}
Thanks Olaf,
Could you please assist with the interpretation of the syntax? Why the protectedfromaccidentaldeletion before and after the pipeline? Also why shouldn’t we indicate within the code whether the property should have a value of true or false?
Get-ADUser does not return the ProtectedFromAccidentalDeletion property by default. Olaf added the -properties parameter to instruct Get-ADUser to return the ProtectedFromAccidentalDeletion property. Since the ProtectedFromAccidentalDeletion is now included in the Get-ADUser output, Where-Object can now be used to filter on its value.
Curtis is absolutely right. And to explain the thing with the where-object: Where-Object evaluates whatever is between the curly braces. If the property is boolian anyway you can omit the comparison.