我正在尝试获取 AD 中的安全组列表,但运气不佳。当我检查 Active Directory 用户和计算机 MMC 时,我看到:
blah.blah.com (top)
Group 1
Group1_1
Group1_2
Group1_2_1
Group2
等等。我需要的是 Group1_2_1 中的所有安全组我尝试使用 DirectoryEntry 和 DirectorySearcher 使用“(&(objectClass = group))”作为搜索过滤器,但我得到了我什至在 Active Directory 用户和计算机 MMC 中找不到的东西。
这就是我在 C# 代码中的内容:
// Binding path.
string strPath = "LDAP://<domain_name>.ABC.DEF.COM";
// Binding object.
DirectoryEntry objADAM = default(DirectoryEntry);
// Group Results.
DirectoryEntry objGroupEntry = default(DirectoryEntry);
// Search object.
DirectorySearcher objSearchADAM = default(DirectorySearcher);
// Results collection.
SearchResultCollection objSearchResults = default(SearchResultCollection);
// Construct the binding string.
List<string> result = new List<string>();
// Get the AD LDS object.
try
{
objADAM = new DirectoryEntry(strPath);
objADAM.RefreshCache();
}
catch (Exception e)
{
throw e;
}
// Get search object, specify filter and scope,
// perform search.
try
{
objSearchADAM = new DirectorySearcher(objADAM);
objSearchADAM.Filter = "Group1_2_1 (groupType:1.2.840.113556.1.4.803:=2147483648)";
//objSearchADAM.Filter = "(&(objectCategory=group)(OU=Group1_2)(OU=Group1_2_1))";
objSearchADAM.SearchScope = SearchScope.Subtree;
objSearchResults = objSearchADAM.FindAll();
}
谢谢。