使用的memberOf時,您必須使用組的完全可分辨名稱:在我的情況CN = MyGroup的,OU =用戶,OU = =組:1.2.840.113556.1.4.1941 ,OU =安全,DC =域,DC = com的是整個專有名稱
(&(objectCategory=person)(objectClass=user)(memberOf:1.2.840.113556.1.4.1941:=CN=MyGroup,OU=User,OU=Groups,OU=Security,DC=domain,DC=com))
您可以通過運行下面的代碼,並把這個過濾器(&(對象類=組得到您的專有名稱組))(name = MyGroup))
Imports System.DirectoryServices
Module Module1
Sub Main()
Dim run As Boolean = True
Dim Filter As String
While run
Console.WriteLine("Enter Filter:")
Filter = Console.ReadLine()
If Filter = "exit" Then
run = False
Else
checkFilter(Filter)
End If
End While
End Sub
Function checkFilter(Filter As String) As Boolean
Dim search As New DirectorySearcher("LDAP://dc=Domain,dc=com")
Try
search.Filter = Filter
search.PropertiesToLoad.Add("name")
search.PropertiesToLoad.Add("distinguishedName")
search.SearchScope = SearchScope.Subtree
Dim results As SearchResultCollection = search.FindAll()
If results Is Nothing Then
Console.WriteLine("Nothing")
Return False
Else
If results.Count() = 0 Then
Console.WriteLine("non found")
End If
Dim result As SearchResult
For Each result In results
Console.WriteLine(result.Properties("name")(0).ToString())
Console.WriteLine(result.Properties("distinguishedName")(0).ToString())
'For Each prop In result.Properties("members")
' Console.WriteLine(prop.ToString())
'Next
Next
Console.WriteLine(String.Format("{0} Users Found", results.Count()))
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Return True
End Function
End Module
謝謝特里。但我對LDAP很陌生,不太瞭解這個過濾器的概念。您能否幫我解釋兩種語法,以及兩者在服務器解釋方面有何不同? –
也許這個鏈接將幫助:[廣告搜索過濾器語法](http://msdn.microsoft.com/en-us/library/windows/desktop/aa746475(v = vs.85).aspx) –
嗨, 我嘗試通過更改過濾器,但仍然無法檢索任何搜索條目。我也拋棄了過濾器: filter(&(objectclass = *)(memberof:1.2.840.113556.1.4.1941:= cn = gasaxena)) 關於我可能缺少的任何指針?是否有任何我們需要打開AD服務器以使此搜索查詢工作的旋鈕? –