尝试获取用户所属的所有组,包括主要组:
做这样的事情:
DirectoryEntry entry = new DirectoryEntry(LDAP:/domainXYZ, userx, passwordx);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = String.Format("(&(objectClass=user)(userPrincipalName={0}{1}))", userY, LDAP://domainXYZ);
SearchResultCollection resultColln= searcher.FindOne();
string actualGroupName =string.empty;
string grp ="";
foreach (SearchResult singleRes in resultColln)
{
foreach (object value in singleRes.Properties["memberof"])
{
grp = value.ToString();
Console.WriteLine("group:{0} ", grp);
}
}
这给了我除主要组之外的所有组。除了其他组之外,有没有办法获得主要组名称?primaryGroupID