pj483
December 24, 2022, 2:03pm
1
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?
Olaf
December 24, 2022, 2:14pm
2
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"'
pj483
December 24, 2022, 3:05pm
3
Err… Surely there’s no point to “-eq” if I need to also use “-ne”
Olaf
December 24, 2022, 3:06pm
4
Did you try it? Did it work?
pj483
December 24, 2022, 3:40pm
5
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 .
mawazo
December 24, 2022, 6:00pm
6
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')"
1 Like
Matt
December 27, 2022, 1:40am
7
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.