[Last Call] Learn how to a build a cloud-first strategyRegister Now


searching through AD regardless the case of the username letters

Posted on 2009-12-20
Medium Priority
Last Modified: 2013-12-24
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 !!!

Question by:nayel
  • 3
  • 2

Expert Comment

ID: 26090000
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.

Author Comment

ID: 26090028
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 !
LVL 71

Expert Comment

by:Chris Dent
ID: 26090191

LDAP searches like this are not case sensitive.

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks


Author Comment

ID: 26090384
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
LVL 71

Accepted Solution

Chris Dent earned 2000 total points
ID: 26090400

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 & "))"


Author Comment

ID: 26095176
so how i will use this filter syntax in the vbscript code to get the user object and read and edit his attributes ?

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question