活动目录搜索不返回所有用户
问题描述:
我有代码来填充VB.net应用程序中的用户id下拉列表。一些用户名不会被返回。我得到1000多个返回,所以它似乎不是1000的限制。如果我将(sAMAccountName = Kry *)添加到搜索过滤器,则返回未出现的用户(名称以kry开头)。任何帮助,将不胜感激。谢谢!活动目录搜索不返回所有用户
Private Sub PopSecurityUser()
cboUser.Items.Clear()
Dim SearchRoot As DirectoryEntry = ActiveDirectory.Forest.GetCurrentForest.RootDomain.GetDirectoryEntry '< More portable. Discover domain root DirectoryEntry rather than hard coding a Global Catalog.
Dim AdObj As System.DirectoryServices.SearchResult
Dim Searcher As New DirectorySearcher(SearchRoot)
With Searcher
.PropertiesToLoad.Add("sAMAccountName")
.SearchScope = SearchScope.Subtree
.Filter = "(&(!objectClass=contact)(objectCategory=person)(objectClass=user))" '< Exclude contacts because they don't have a sAMAccountName property.
.ReferralChasing = ReferralChasingOption.All '< Causes lookups to follow LDAP referrals if the object doesn't exist on the queried domain controller.
End With
For Each AdObj In Searcher.FindAll
If Not IsNumeric(AdObj.Properties("sAMAccountName")(0).ToString.Substring(0, 1)) Then
cboUser.Items.Add(AdObj.Properties("sAMAccountName")(0))
End If
Next
cboUser.Sorted = True
End Sub
答
DirectorySearcher.SizeLimit属性默认设置为1,000。我发现另一个有关这种确切情况的StackOverflow问题,显然有两种解决方法。我指的StackOverflow答案在这里:https://stackoverflow.com/a/3488957/1920035
我得到1232个用户,所以我不认为这是1000的限制。我最终添加(userAccountControl = 512)排除禁用的帐户,现在我得到约800行返回,包括丢失的用户。 – gcresse
噢,对不起,我一定忽略了“......超过1000个返回”的声明。尽管如此,我很高兴你能找到解决方案。 – David