searching through AD regardless the case of the username letters

friends,
i have syncing script to sync account information between our BANNER (oracle) system and AD accounts, i'm reading from the BANNER and search for same ID in AD usernames to get the AD user object and update the information here is the searching lines:

==========================================
Set ADConnection = CreateObject("ADODB.Connection")
Set ADCommand = CreateObject("ADODB.Command")
ADConnection.Provider= "ADsDSOObject"
ADConnection.Open "Active Directory Provider"
Set ADCommand.ActiveConnection = ADConnection
ADCommand.CommandText= "SELECT mobile,telephonenumber,title,employeeid,company,department,departmentnumber,mail,userPrincipalName,Name,givenname,sn,initials,ADsPath,displayName,userCategory ,distinguishedName,sAMAccountName FROM 'LDAP://DC=aa,DC=uaeu,DC=ac,DC=ae' WHERE objectCategory='User' AND sAMAccountName='" & LDAP_Username & "'"
ADCommand.Properties("Page Size")       = 1000
ADCommand.Properties("Searchscope") = 2
Set ADRecordSet = ADCommand.Execute
=================================================

now in line:
--------------------------------
ADCommand.CommandText= "SELECT mobile,telephonenumber,title,employeeid,company,department,departmentnumber,mail,userPrincipalName,Name,givenname,sn,initials,ADsPath,displayName,userCategory ,distinguishedName,sAMAccountName FROM 'LDAP://DC=aa,DC=uaeu,DC=ac,DC=ae' WHERE objectCategory='User' AND sAMAccountName='" & LDAP_Username & "'"
-----------------------------------------------------

we have some sAMAccountName has a capital letters, i already converting the varaible LDAP_Username  to lower case before running the statement, but how can i converting the sAMAccountName to lower case ?? i used the LOWER() function but it not working with AD Provider !!!


     
nayelAsked:
Who is Participating?
 
Chris DentPowerShell DeveloperCommented:

Oh I see. Can you use or have you tried the VbScript LCase function on the string?

<snip> .. sAMAccountName='" & LCase(LDAP_Username) & "' .. <snip>

It should have the same effect, without trying to use the SQL function.

I rarely use the SQL form of the query these days so case sensitivity may be a feature of that. You might also try the same query with this form of filter:

(&(objectClass=user)(objectCategory=person)(sAMAccountName=" & LDAP_Username & "))"

Chris
0
 
JonasHaglundCommented:
As I understand it, you have an ID that is similar to a sAMAccount and you want to search through your AD to find that particular user. Another way of doing this is looping through all users in the AD and do the comparison. Here is an example: http://rogierg.blogspot.com/2009/06/vbscript-find-username-by-ad-fullname.html.
0
 
nayelAuthor Commented:
Dear JonasHaglund:, we have more than 20000 users in AD so this will take alot of time to get one user, u can imagin this will run 20000 times !
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
Chris DentPowerShell DeveloperCommented:

LDAP searches like this are not case sensitive.

Can you share how you've used Lower()? And any error messages returned.

Chris
0
 
nayelAuthor Commented:
i use like this:
-------------------------------------------------
ADCommand.CommandText                         = "SELECT mobile,telephonenumber,employeeid,company,department,departmentnumber,mail,userPrincipalName,Name,givenname,sn,initials,ADsPath,displayName,userCategory ,distinguishedName,sAMAccountName FROM 'LDAP://DC=aa,DC=uaeu,DC=ac,DC=ae' WHERE objectCategory='User' AND Lower(sAMAccountName)='farag.kotb'"
-------------------------------------------------
and i got this error:

Provider: One or more errors occurred during processing of command.

-------------------------------------------------

once i put the username value "Farag.Kotb" not "farag.kotb" and not using Lower() i got a result , so its case sensitive
0
 
nayelAuthor Commented:
so how i will use this filter syntax in the vbscript code to get the user object and read and edit his attributes ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.