Searching AD with VB .NET
Does anybody know of a way to search Active Directory for a given string (say a users surname or part of it)?
I have this code from Microsoft's Scripting Center:-
Code:
Dim objConnection = CreateObject("ADODB.Connection")
objConnection.Open("Provider=ADsDSOObject;")
Dim objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=npf,dc=internal>;(&(objectCategory=User)" & _
"(displayName=" & SearchParameter & "));displayName;subtree"
Dim objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
MessageBox.Show("sAMAccountName: " & SearchParameter & " does not exist.")
Else
MessageBox.Show(SearchParameter & " exists " & objRecordSet.RecordCount & " time(s).")
End If
objConnection.Close()
(the SearchParameter is passed to the function and does work if you enter wildcards characters).
However, there doesn't seem to be a way to interrogate the objRecordSet object more fully, say for the users actual name, user id etc etc.
I can only return a recordcount, not the values contained within it.