我有代码填充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
答案 0 :(得分:0)
默认情况下,DirectorySearcher.SizeLimit属性设置为1,000。我找到了关于这种确切情况的另一个StackOverflow问题,显然有两种解决方法。我所指的StackOverflow答案在这里:https://stackoverflow.com/a/3488957/1920035