Im back... with more ActiveDirectory questions.
Firslty I will show you my output:
The issue is that basically the wildcard operator * seems to not be working correctly when running my query function against an active directory.
If I run a search of a partial last name where the attribute is lastname=mobb* it will find me, and also as shown in the above code I can output my exact department as being "Business Excellence" as shown in the second output.
If I run a search of a partial departmet such as departmenttext= Buss* it will not find any records as shown in the first output.
However, If I remove the wildcard from the department search and use the EXACT name so: departmenttext= Business Excellence I get all members of my department to show.
Does anyone have any idea why the wildcard does not work for this attribute? Infact I have just found that it does not work on a second, whilst the other 14 attributes it works correctly! I really cant imagine that some attributes are not searchable via a wildcard in AD.
My full code is below:
Firslty I will show you my output:
Code:
Output 1 - Search based on department name: The filter string: (&(objectClass=*)(departmentText=Business*)) Records returned: 0 Output 2 - Search based on last name of person: The filter string: (&(objectClass=*)(LastName=Mobb*)) Records returned: 1 Department: Business Excellence
If I run a search of a partial last name where the attribute is lastname=mobb* it will find me, and also as shown in the above code I can output my exact department as being "Business Excellence" as shown in the second output.
If I run a search of a partial departmet such as departmenttext= Buss* it will not find any records as shown in the first output.
However, If I remove the wildcard from the department search and use the EXACT name so: departmenttext= Business Excellence I get all members of my department to show.
Does anyone have any idea why the wildcard does not work for this attribute? Infact I have just found that it does not work on a second, whilst the other 14 attributes it works correctly! I really cant imagine that some attributes are not searchable via a wildcard in AD.
My full code is below:
Code:
Public Function UserInfoo(SearchString As String, SearchBase As String)
Dim rs As ADODB.Recordset
Dim sBase As String
Dim sFilter As String
Dim sDomain As String
Dim sAttribs As String
Dim sDepth As String
Dim sQuery As String
Dim sAns As String
Dim user As IADsUser
Dim counter As Integer
Dim strHeaders As String
Dim Searcher As String
On Error GoTo ErrHandler:
'Select our Actual SearchBase based on incoming string supplied from form
Select Case SearchBase
Case "Last Name"
Searcher = "LastName"
Case "First Name"
Searcher = "givenName"
Case "Gender"
Searcher = "gender"
Case "Company"
Searcher = "company"
Case "Department"
Searcher = "departmentText"
Case "SCD ID"
Searcher = "scdid"
Case "Function"
Searcher = "mainfunction"
Case "Cost Unit"
Searcher = "costlocation"
Case "Nickname"
Searcher = "nickname"
Case "Organisation"
Searcher = "o"
Case "Locality"
Searcher = "localitynational"
Case "Phone"
Searcher = "mobile"
Case "GID"
Searcher = "tcgid"
Case "Email"
Searcher = "mail"
Case Else
MsgBox "You must select a parameter to base your search on.", vbInformation, "Error.."
Exit Function
End Select
'create and setup our ado connection with anonymous connectivity
Set ado = CreateObject("ADODB.Connection")
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = ""
ado.Properties("Password") = ""
ado.Properties("Encrypt Password") = False
ado.Open "ADS-Anon-Search"
'The basic directory we want to look in to, domain filtering down
servername = "scd2ldap.mycompany.net/l=NUT S,ou=E F,o=mycompany,c=GB"
'Create LDAP connection string for directory based on server address
sBase = "<LDAP://" & servername & ">"
'Look within all objectclasses and search for our lastname attribute using a like clause.
sFilter = "(&(objectClass=*)(" & Searcher & "=" & SearchString & "*" & "))"
'Attributes
sAttribs = "adsPath"
'Depth to look in to when finding attributes, subTree of user found in search
sDepth = "subTree"
'Overall query string to run for our connection
sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
'Set headers of listbox ready to be populated with data returned from query
strHeaders = "Given Name;Last Name;Gender;Company;Department;Locality;E mail;function;phone;GID;CN;costunit;nickname;title;organisation;scdId"
'Set counter to 0 for counting number of times we have run through our function loop
counter = 0
'Set recordset equal to that of the executed query, recordset will contain all data returned
Set rs = ado.Execute(sQuery)
'Implement the headers for the listbox
Forms.form1.listbox1.RowSource = strHeaders
'Start our do until loop based on number of records in our recordset against number of times looped
Do Until counter = rs.RecordCount
Set user = GetObject(rs("adsPath"))
sAns = ""
With user
On Error Resume Next
sAns = sAns & Trim(StripString(.givenName)) & ";" & Trim(StripString(.LastName)) & ";" & Trim(.gender) & ";" & Trim(StripString(.company)) & ";" & Trim(StripString(.departmenttext)) & ";" & Trim(StripString(.localitynational)) & ";" & Trim(StripString(.mail)) & ";" & Trim(StripString(.mainFunction)) & ";" & Trim(StripString(.mobile)) & ";" & Trim(StripString(.tcgid)) & ";" & Trim(StripString(.cn)) & ";" & Trim(StripString(.costlocation)) & ";" & Trim(StripString(.nickname)) & ";" & Trim(StripString(.Title)) & ";" & Trim(StripString(.o)) & ";" & Trim(StripString(.scdid)) & ";"
End With
Forms.form1.listbox1.AddItem (sAns)
rs.MoveNext
counter = counter + 1
Loop
'Success
Completed:
If Not rs Is Nothing Then
If rs.State <> 0 Then rs.Close
Set rs = Nothing
End If
If Not ado Is Nothing Then
If ado.State <> 0 Then ado.Close
Set ado = Nothing
End If
Exit Function
ErrHandler:
If Not rs Is Nothing Then
If rs.State <> 0 Then rs.Close
Set rs = Nothing
End If
If Not ado Is Nothing Then
If ado.State <> 0 Then ado.Close
Set ado = Nothing
End If
MsgBox Err.Description & " " & Err.Number
Resume Completed
End Function
Comment