在 C# 中查询 Active Directory 时出现奇怪的问题。
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();
但结果不一样:
PrincipalSearcher
返回14组DirectorySearcher
返回12组
好吧,这是错误还是我错过了什么?
谢谢