Tim
Tim

Reputation: 4101

AD returns computer object when searching for users

I've just spent three hours figuring this out and hope someone can tell me what happened here.

I have AD code that searches for users. In our domain, usernames are similar to computernames (the convention is along the lines of first + last + computer name).

When I run the following query, I sometimes get a computer, sometimes I get a user:

(&(objectClass=user)(anr=username))

When I use SamAccountName instead of anr, I always get a user. I had to change my code to do this.

Is there any reason the anr query would override the objectClass query? (I would think this code is asking for users)

Upvotes: 0

Views: 60

Answers (1)

Brian Desmond
Brian Desmond

Reputation: 4503

That's expected. Computers derive from users in AD's class hierarchy. Use this filter and you'll be good.

(&(objectCategory=person)(objectClass=user)(anr=username))

Upvotes: 1

Related Questions