首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Active Directory :获取所有“安全组”

Active Directory :获取所有“安全组”
EN

Stack Overflow用户
提问于 2011-09-06 16:47:30
回答 2查看 2.6K关注 0票数 1

我想让所有的组“安全组”在活动食堂中可用。

有什么想法吗?

谢谢,

EN

回答 2

Stack Overflow用户

发布于 2011-09-06 17:11:59

由于您使用的是.NET 3.5或更高版本,因此可以使用PrincipalSearcher和“按示例查询”主体来执行搜索:

代码语言:javascript
复制
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// define a "query-by-example" principal - here, we search for a GroupPrincipal 
// with the security group flag set
GroupPrincipal qbeGroup = new GroupPrincipal(ctx);
qbeGroup.IsSecurityGroup = true;

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);

// find all matches
foreach(var found in srch.FindAll())
{
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
}

如果您还没有,请阅读MSDN文章Managing Directory Security Principals in the .NET Framework 3.5,它很好地展示了如何充分利用System.DirectoryServices.AccountManagement中的新特性

票数 3
EN

Stack Overflow用户

发布于 2015-05-11 17:24:47

试试这条路

代码语言:javascript
复制
           DirectoryEntry ent1 = new DirectoryEntry("LDAP://" + _path, 
           "adminUser", "***********");

            DirectorySearcher dSearch = new DirectorySearcher(ent1);

            dSearch.Filter = "(&(objectClass=group))";

            dSearch.SearchScope = SearchScope.Subtree;

            SearchResultCollection results = dSearch.FindAll();
            List<string> groupNames = new List<string>();

            for (int i = 0; i < results.Count; i++)
            {
                DirectoryEntry de = results[i].GetDirectoryEntry();

                groupNames.Add(de.Name.Replace("CN=", ""));


            }

它正在为我工作:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7317205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档