我想使用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
发布评论