获得集团利用DirectoryServices.AccountManagement OU

编程入门 行业动态 更新时间:2024-10-27 07:30:21
本文介绍了获得集团利用DirectoryServices.AccountManagement OU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用AccountManagement列出所有组的组织单位。

I'd like to use AccountManagement to list all the groups in an Organizational Unit.

下面的代码片段可与的DirectoryServices,但我将不得不实例化GroupPrincipal与结果的的DirectoryEntry路径(这感觉就像一个肮脏的修复)。

The following snippet works with DirectoryServices but I would have to instanciate GroupPrincipal with the DirectoryEntry path in the result (which feels like a dirty fix).

DirectoryEntry root = new DirectoryEntry("LDAP://OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local") DirectorySearcher ds = new DirectorySearcher(root); ds.Filter = "(objectCategory=group)"; SearchResultCollection results = ds.FindAll();

有没有人一个想法?

Has anyone an idea?

谢谢!

推荐答案

您可以设置 PrincipalContext 的OU要开始搜索,并使用 PrincipalSearcher 级的 System.DirectoryService.AccountManagement 来完成你所需要的,是这样的:

You can set the PrincipalContext to the OU where you want to start the search and use the PrincipalSearcher-class in System.DirectoryService.AccountManagement to accomplish what you need, like this:

PrincipalContext yourOU = new PrincipalContext(ContextType.Domain, "mycompany.local", "OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local"); GroupPrincipal findAllGroups = new GroupPrincipal(yourOU, "*"); PrincipalSearcher ps = new PrincipalSearcher(findAllGroups); foreach(var group in ps.FindAll()) { Console.WriteLine(group.DistinguishedName); } Console.ReadLine();

更多推荐

获得集团利用DirectoryServices.AccountManagement OU

本文发布于:2023-06-06 02:24:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/534751.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:集团   DirectoryServices   OU   AccountManagement

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!