I have strange problem when querying Active Directory in C#.
var ctx = new PrincipalContext(ContextType.Domain, "adr", "usr", "pwd");
var entry = new DirectoryEntry("LDAP://" + adr, usr, pwd);
var searcher = new DirectorySearcher(entry) { Filter = "(&(sAMAccountName=user_to_search))", PageSize = 2000 };
foreach (SearchResult searchUser in searcher.FindAll())
{
// groups
var groups = searchUser.GetPropertyValues("memberof");
}
var groups = UserPrincipal.FindByIdentity(ctx, "usr_to_search").GetGroups(ctx).ToList();
But the results are not the same:
- the
PrincipalSearcherreturns 14 groups - the
DirectorySearcherreturns 12 groups
Well, is this bug or did I miss something?
Thanks
Oh my god, i have mistake in my extension method ( i < prop.count – 1).
Sorry for stupid question.