# Get-ADObject not showing enabled AD Object result?

**URL:** <https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828>\
**Category:** PowerShell Help\
**Created:** [August 19, 2020, 4:35pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828 "2020-08-19T16:35:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [August 19, 2020, 4:35pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/1 "2020-08-19T16:35:21Z")

</div>

People,

I need some help in explaining and modifying the below script, as to why the below script is not returning any result at all.

```
$filter = '
    (
        ObjectClass -eq "user" -or
        ObjectClass -eq "computer"
    ) -and 
    Enabled -eq $true
' 
Get-ADObject -Filter $filter
```

But when the section **Enabled -eq $true** is removed, all objects is returned?

&nbsp;

---

<div class="post-metadata">

**Author:** ![adminofthings](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adminofthings](https://forums.powershell.org/u/adminofthings)\
**Post date:** [August 19, 2020, 7:54pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/2 "2020-08-19T19:54:28Z")

</div>

`Get-ADObject` does not output an `Enabled` property for user and computer accounts. If you use `Get-ADUser` or `Get-ADComputer`, you get that property.

You could instead attempt to look at the `UserAccountControl` attribute. The second bit (decimal `2`) will be on for disabled accounts.

```
$filter = "(objectClass -eq 'user' -or objectClass -eq 'computer') -and -not UserAccountControl -band 2"
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [August 19, 2020, 9:08pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/3 "2020-08-19T21:08:11Z")

</div>

Wow, this is cool and working.

thanks @admin

---

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [August 19, 2020, 9:17pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/4 "2020-08-19T21:17:53Z")

</div>

What about using this pipe:

**| Where-Object {@(‘user’, ‘computer’) -contains $\_.objectClass}**

Would it be faster or more accurate?

---

<div class="post-metadata">

**Author:** ![adminofthings](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adminofthings](https://forums.powershell.org/u/adminofthings)\
**Post date:** [August 19, 2020, 9:27pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/5 "2020-08-19T21:27:24Z")

</div>

`-Filter` is almost always faster than piping to `Where`. This is especially true for indexed AD attributes. There are cases where the `where()` method is faster if you use a favorable mode for the situation.

---

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [August 19, 2020, 9:31pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/6 "2020-08-19T21:31:23Z")

</div>

[quote quote=251141] -Filter is almost always faster than piping to Where. This is especially true for indexed AD attributes. There are cases where the where() method is faster if you use a favorable mode for the situation.

[/quote]

Thank you so much for the explanations 🙂

---

<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:29pm UTC](https://forums.powershell.org/t/get-adobject-not-showing-enabled-ad-object-result/14828/7 "2024-05-16T20:29:01Z")

</div>


