VBScript AD Select all users beginning with!!!

Newbie Member
6Aug2007,18:56   #1
covachero's Avatar
Hi to all you guys, this is my first thread, well this is my question: I´m using an LDAP SQL statement to retireve a user OU, but I want to look the OUs for all users beginning with a letter Example: A%

This is the code I use:

Code:
Set rs = CreateObject("adodb.recordset")
Connstring = "Provider=ADsDSOObject"

strSQL = "SELECT distinguishedName FROM 'LDAP://ou=es,dc=prg-dc,dc=dhl,dc=com' WHERE sAMAccountName = 'jdoe'"
	
rs.Open strSQL, Connstring
    Do Until rs.EOF
WScript.Echo rs("distinguishedName")
Loop
rs.close

strUserDN = LCase(fullpath)
		
Set objUser = GetObject ("LDAP://" & strUserDN)
Thanks a lot...

Last edited by shabbir; 6Aug2007 at 19:48.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code
Go4Expert Founder
6Aug2007,19:50   #2
shabbir's Avatar
I am not a LDAP SQL expert but you can refer to the LIKE operator which we have.

Code:
....  WHERE sAMAccountName LIKE 'A%'
Newbie Member
6Aug2007,20:00   #3
covachero's Avatar
Thanks for the repply, I though the same but it gives me this error when run it :
Provider: One or more errors occurred during processing of command.

It doesn't give an error number or anything but that
Team Leader
13Aug2007,11:17   #4
jwshepherd's Avatar
Try
Code:
....WHERE sAMAccountName LIKE 'A%'
instead of percentage
Newbie Member
14Aug2007,12:45   #5
covachero's Avatar
Quote:
Originally Posted by jwshepherd
Try
Code:
....WHERE sAMAccountName LIKE 'A%'
instead of percentage
Don't understando (Instead of percentage) what I'm suppose to use instead of percentage?

Thank you for your repply.
Team Leader
14Aug2007,12:50   #6
jwshepherd's Avatar
sorry try an asterick instead of a percent sign.*
Newbie Member
14Aug2007,13:36   #7
covachero's Avatar
Thanks a lot, with the * works just great.
Team Leader
14Aug2007,19:01   #8
jwshepherd's Avatar
no problem