# AD Powershell

**URL:** <https://forums.powershell.org/t/ad-powershell/8920>\
**Category:** PowerShell Help\
**Created:** [June 28, 2017, 9:01am UTC](https://forums.powershell.org/t/ad-powershell/8920 "2017-06-28T09:01:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [June 28, 2017, 9:01am UTC](https://forums.powershell.org/t/ad-powershell/8920/1 "2017-06-28T09:01:09Z")

</div>

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}

Regards,

Yeta

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 28, 2017, 9:48am UTC](https://forums.powershell.org/t/ad-powershell/8920/2 "2017-06-28T09:48:05Z")

</div>

Could you please format your code as code? Thanks.

```
get-aduser -Filter * -Properties ProtectedFromAccidentalDeletion | where-object {$_.ProtectedFromAccidentalDeletion}
```

---

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [June 28, 2017, 10:53am UTC](https://forums.powershell.org/t/ad-powershell/8920/3 "2017-06-28T10:53:48Z")

</div>

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?

Thanks again…

---

<div class="post-metadata">

**Author:** ![curtis-smith](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/curtis-smith/32/121_2.png) [@curtis-smith](https://forums.powershell.org/u/curtis-smith)\
**Post date:** [June 28, 2017, 11:36am UTC](https://forums.powershell.org/t/ad-powershell/8920/4 "2017-06-28T11:36:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 28, 2017, 12:43pm UTC](https://forums.powershell.org/t/ad-powershell/8920/5 "2017-06-28T12:43:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yeta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/yeta/32/1922_2.png) [@yeta](https://forums.powershell.org/u/yeta)\
**Post date:** [June 29, 2017, 1:23am UTC](https://forums.powershell.org/t/ad-powershell/8920/6 "2017-06-29T01:23:33Z")

</div>

Curtis and Olaf, thanks for the interpretation of the where-object cmdlet. It’s now making sense

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/ad-powershell/8920/7 "2024-05-16T20:38:27Z")

</div>


