Reputation: 22496
I execute a query to Active Directory, that can return both users and groups.
(&(|(&(objectCategory=person)(objectClass=user))(objectCLass=group))(...))
but when I try to get the objectClass property from the resultset I awais get "top"
DirectorySearcher searcher = new DirectorySearcher(baseDirEntry);
searcher.Filter = "(&(|(&(objectCategory=person)(objectClass=user))(objectCLass=group))(|(sAMAccountName=*{0}*)(displayName=*{0}*)(email=*{0}*)))";
//other props
searcher.PropertiesToLoad.Add(AdProperties.OBJECTCLASS);
SearchResultCollection userResult = searcher.FindAll();
foreach (SearchResult rs in userResult)
{
string objectClass = GetProp(rs, AdProperties.OBJECTCLASS);//returns "top" every time
}
How can I find out if an AD object is user or group?
Edit The ObjectCategory proeprty returns a distinguished name like
CN=Person(or Group),CN=Schema,CN=Configuration,DC=...,DC=...,DC=...
So I can parse the string and get the first CN value, but it doesn't look like the best way to do it.
Upvotes: 2
Views: 931
Reputation: 57172
I think the problem could be in your GetProp
method: objectClass is a multi-valued property, and probably in GetProp
you are just returning the first value, which is always "top".
If that's the case, you should check the other values as well.
Otherwise, could you please post the implementation of GetProp
?
Upvotes: 3