假设我有三个活动目录D1
,D2
,D3
。
D2 is group member of D1.
D3 is group member of D2.
因此,如果我想获取D1
的群组成员列表,则结果应为D2
,而不是D2
和D3
。
怎么做?
答案 0 :(得分:1)
将Hashtable变量定义为全局变量。 Hashtable searchingGroups = null;
strGroupDN是主目录列表名称。
private ArrayList getsubDL(string strGroupDN)
{
ArrayList allSubDL = new ArrayList();
searchedGroups.Add(strGroupDN, strGroupDN);
// get nested groups
ArrayList Nestedgroups = new ArrayList();
// find all nested groups in this group
DirectorySearcher ds = new DirectorySearcher();
ds.Filter = String.Format
("(&(memberOf={0})(objectClass=group))", strGroupDN);
foreach (SearchResult sr in ds.FindAll())
{
string grnm = sr.Properties["distinguishedName"][0].ToString();
string grnsamn = sr.Properties["sAMAccountName"][0].ToString();
Nestedgroups.Add(sr.Properties["distinguishedName"][0].ToString());
}
allSubDL.AddRange(Nestedgroups);
return allSubDL;
}
public ArrayList GetsubDLList(string strGroupName)
{
ArrayList allSubDL = new ArrayList();
searchedGroups = new Hashtable();
// find group
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format
("(&(objectCategory=group)(cn={0}))", strGroupName);
search.PropertiesToLoad.Add("distinguishedName");
SearchResult sru = null;
DirectoryEntry group;
try
{
sru = search.FindOne();
}
catch (Exception ex)
{
throw ex;
}
group = sru.GetDirectoryEntry();
allSubDL = getsubDL(group.Properties["distinguishedName"].Value.ToString());
return allSubDL;
}
allSubDL将为您提供子目录列表的详细信息。