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

x
?
Solved

searching through AD regardless the case of the username letters

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


     
0
Comment
Question by:nayel
  • 3
  • 2
6 Comments
 

Expert Comment

by:JonasHaglund
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.
0
 

Author Comment

by:nayel
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 !
0
 
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.

Chris
0
 [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

by:nayel
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
0
 
LVL 71

Accepted Solution

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

Chris
0
 

Author Comment

by:nayel
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 ?
0

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