简体   繁体   English

Active Directory搜索未返回所有用户

[英]Active Directory Search not returning all users

I have code to populate a user id dropdown list within a VB.net application. 我有代码来填充VB.net应用程序中的用户ID下拉列表。 Some user names are not being returned. 某些用户名未返回。 I'm getting more than 1000 returned so it does not appear to be the 1000 limit. 我得到的返回数量超过1000,因此它似乎不是1000的限制。 If I add (sAMAccountName=Kry*) to the search filter, then the user (whose name starts with kry) that was not appearing does get returned. 如果我将(sAMAccountName = Kry *)添加到搜索过滤器,则返回未出现的用户(其名称以kry开头)。 Any help on this would be greatly appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

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

The DirectorySearcher.SizeLimit property is set to 1,000 by default. 默认情况下, DirectorySearcher.SizeLimit属性设置为1,000。 I found another StackOverflow question regarding this exact situation and apparently there are two workarounds. 我发现了另一个有关此确切情况的StackOverflow问题,显然有两种解决方法。 The StackOverflow answer that I am referring to is here: https://stackoverflow.com/a/3488957/1920035 我要指的StackOverflow答案在这里: https : //stackoverflow.com/a/3488957/1920035

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM