从给定AD组中的ActiveDirectory中获取用户列表我有代码可以搜索部门中的所有用户:stringDepartment=“Billing";DirectorySearcherLdapSearcher=newDirectorySearcher();LdapSearcher.PropertiesToLoad.Add("displayName");LdapSearcher.PropertiesToLoad.Add("cn");LdapSearcher.PropertiesToLoad.Add("部门");LdapSearcher.PropertiesToLoad.Add("标题");LdapSearcher.PropertiesToLoad.Add("memberOf");LdapSearcher.Filter=string.Format("(&(objectClass=user)(department={0}))",Department);SearchResultCollectionsrc=LdapSearcher.FindAll();如果我只希望“经理只读”AD组中的每个人,过滤器需要是什么样子?我错了吗?查看您的搜索,我有一些要点。首先,搜索使用objectClass(非索引)而不是objectCategory(索引)。此查询存在巨大的性能问题。您总是希望根据要检索的内容将两者结合起来:(&(objectCategory=person)(objectClass=user))=Allusers(nocontacts)(&(objectCategory=person)(objectClass=contact))=Allcontacts(nousers)(&(objectCategory=person))=所有用户和联系人至于在组中查找用户,您可以枚举特定组的成员对象列表。在组对象的成员属性中是每个用户的distinguishedName。本文描述了枚举一个组的成员...不要忘记您可能必须处理父组的嵌套组,因为没有使用LDAP查询处理此问题的默认方法。为此,您可能需要评估成员对象是否是一个组,然后获取该子组的成员属性。最后,您应该养成为查询指定dns前缀的习惯。没有DNS前缀:LDAP://ou=ouname,dc=domain,dc=com有DNS前缀(这三个都有效):LDAP://servername/ou=ouname,dc=domain,dc=comLDAP://servername.domain.com/ou=ouname,dc=domain,dc=comLDAP://domain.com/ou=ouname,dc=domain,dc=com单个域不会给您造成太大问题,但是当没有这个此外,当您尝试在多域环境中运行搜索时,您会被咬住。希望这可以帮助您更接近您的目标。我总能找到Howto:(Almost)EverythinginActiveDirectoryviaC#这有助于解决大多数AD问题。如果您已经知道组的AD路径,则可能更容易在其上打开DirectoryEntry并从那里执行DirectorySearcher。使用(DirectoryEntryde=newDirectoryEntry("LDAP://somedomain/CN=FooBar")){DirectorySearchersearch=newDirectorySearcher(de,("(objectClass=user)"));}Searcher上还有一个flag,使用至于是否下钻到子容器,手边忘了名字了。我使用以下代码(来自http://blogs.technet.com/b/brad_rutkowski/archive/2008/04/15/c-getting-members-of-a-group-the-easy-way-with-net-3-5-discussion-groups-nested-recursive-security-groups-etc.aspx)它工作正常。以上是C#学习教程:从给定AD组的ActiveDirectory中获取用户列表共享的所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注——IListgetMembers(stringdomainName,stringgroupName){GroupPrincipalgrp=GroupPrincipal.FindByIdentity(ctx,IdentityType.Name,groupName);if(grp==null){thrownewApplicationException("我们没有在该域中找到该组,也许该组驻留在不同的域中?");}IList成员=newList();foreach(principalpingrp.GetMembers(true)){成员。添加(页名);//可以添加更多的属性,samaccountname、UPN、DN、对象类型等...}grp.Dispose();ctx.Dispose();回归会员;}//使用System搜索群组并列出群组成员;使用System.Linq;使用系统文本;使用System.Threading.Tasks;使用System.DirectoryServices.AccountManagement;命名空间ExportActiveDirectoryGroupsUsers{类程序{静态voidMain(string[]args){if(args==null){Console.WriteLine("argsisnull,useage:ExportActiveDirectoryGroupsUsersOutputPath");//检查空数组}else{Console.Write("argslengthis");Console.WriteLine(args.Length);//Writearraylengthfor(inti=0;i本文摘自网络,不代表立场,如涉及侵权,请点击右侧联系管理员删除,如有转载,请注明出处:
