Get-ADObject -Filter not working?

Hi all. I am running the following code:

[pscustomobject]$resultSet = Get-ADObject -Filter '(objectClass -eq "user" -or objectClass -eq "group" -or objectClass -eq "organizationalUnit")' -Server ...

but in the $resultSet array, I’m getting values where “objectClass” equals “computer”. Any ideas what’s going on?

If you don’t like to get computers you should exclude them. :wink:

Get-ADObject -Filter '(objectClass -eq "user" -or 
    objectClass -eq "group" -or 
    objectClass -eq "organizationalUnit") -and 
    objectClass -ne "computer"'

Err… Surely there’s no point to “-eq” if I need to also use “-ne” :face_with_raised_eyebrow:

Did you try it? Did it work?

No. As I’m parsing the resulting array based on the “objectClass” value, I just ignore the entries I don’t want. My question was more about why they’re being returned at all.

searched online and found this. hope it helps

after reading, tested below seems to work

 Get-ADObject -Filter "(objectClass -eq 'user' -and objectCategory -eq 'person') -or (objectClass -eq 'group') -or (objectClass -eq 'organizationalUnit')"
1 Like

Lesson learned is the code is always right. Meaning it did exactly what you said to do, just not what you wanted it to do. When this happens, asking for help is not necessarily wrong, but diving back into the documentation will clarify what is going on.