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.
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”
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
searched online and found this. hope it helps
Before you search a directory, consider how your search will perform based on your approach. The data and properties to be returned affect where you bind to start a search, the depth of your search, your query filter, and search performance.
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')"
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.