Hajji Majide
Hajji Majide

Reputation: 11

Searching User In Active Directory By Full Name

I'm looking for the way to search users in Active Directory using VBScript. I can search by username or any Active Directory using ADODB Connection:

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.Properties("SearchScope") = 2
objCommand.CommandText = "SELECT userWorkstations,sAMAccountName,Mail,name,DisplayName,distinguishedName FROM 'LDAP://dc=NESTLE,dc=com' WHERE objectCategory='user' AND name='" & VaR5 & "'"
Set objRecordSet = objCommand.Execute

But I'd like to find a user with his full name, for example "John Doe" (User:Jdoe). So like in the AD Users and Computers interface we could search by "John Doe".

Upvotes: 1

Views: 1129

Answers (2)

Hajji Majide
Hajji Majide

Reputation: 11

Ok it seems to work by workaround Using Outlook Function

Dim myOlApp

Dim myOlNameSpace

Dim objFolder

Set myOlApp = CreateObject("Outlook.Application")

Set myOlNameSpace = myOlApp.GetNamespace("MAPI")

Set myRecipient = myOlNameSpace.CreateRecipient("Martin Pierre-François")

myRecipient.Resolve

msgbox myRecipient

And after I do my search in AD with displayName Attribute

Thanks For All

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

Change

"... name='" & var5 & "'"

to either

"... displayName='" & var5 & "'"

or

"... sn='" & lastname & "' and givenName='" & firstname & "'"

For the latter you need 2 variables: one with the first and the other with the last name.

Upvotes: 0

Related Questions