LDAP Query to search a user in AD using his partial last name

Dim User as object

Set User = GetUserObjectFromPartialName(‘doe’)

Msgbox User.FullName & User.sAMAccountName


Public Function GetUserObjectFromPartialName(ByVal PartialName As String) As Object
On Error Resume Next
Set rs = CreateObject(“adodb.recordset”)
rs.ActiveConnection = “provider=adsdsoobject”

rs.Open “<LDAP://dc=sl,dc=ad,dc=csx,dc=com>;(&(objectCategory=Person)” & _
“(objectClass=OrganizationalPerson)(name=” & PartialName & “*));adspath;subtree”

If Not rs.EOF Then
Set GetUserObjectFromPartialName = GetObject(rs(0))
End If
End Function


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s