我正在尝试查询分配给LDAP中特定departmentnumber
的用户列表,我知道这应该是一个大约100的列表。以下代码只撤回一个成员(姓氏开始)有了T,所以在我看来它似乎只返回最后一个值):
Dim userIds As IEnumerable(Of String) = {"7871"}
For Each i As String In userIds
Dim de As New DirectoryEntry("LDAP://test.net:389/DC=test,DC=net")
Dim LdapFilter As String = "(departmentNumber=" & i & ")"
Dim searcher As New DirectorySearcher(de, LdapFilter)
Dim result As SearchResult = searcher.FindOne()
Dim res As SearchResultCollection = searcher.FindAll()
Dim item As ListViewItem = ListView1.Items.Add(i)
item.SubItems.Add(result.Properties("givenName")(0).ToString())
item.SubItems.Add(result.Properties("cn")(0).ToString())
item.SubItems.Add(result.Properties("userPrincipalName")(0).ToString())
Next
答案 0 :(得分:1)
这有效:
Dim userIds As IEnumerable(Of String) = {"7871"}
For Each i As String In userIds
Dim de As New DirectoryEntry("LDAP://test.net:389/DC=test,DC=net")
Dim LdapFilter As String = "(departmentNumber=" & i & ")"
Dim searcher As New DirectorySearcher(de, LdapFilter)
Dim result As SearchResult
Dim res As SearchResultCollection = searcher.FindAll()
For Each result In res
Dim item As ListViewItem = ListView1.Items.Add(i)
item.SubItems.Add(result.Properties("givenName")(0).ToString())
item.SubItems.Add(result.Properties("cn")(0).ToString())
item.SubItems.Add(result.Properties("userPrincipalName")(0).ToString())
Next
Next