VBScript AD Select all users beginning with!!!

covachero's Avatar, Join Date: Aug 2007
Newbie Member
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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I am not a LDAP SQL expert but you can refer to the LIKE operator which we have.

Code:
....  WHERE sAMAccountName LIKE 'A%'
covachero's Avatar, Join Date: Aug 2007
Newbie Member
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
jwshepherd's Avatar, Join Date: Aug 2007
Team Leader
Try
Code:
....WHERE sAMAccountName LIKE 'A%'
instead of percentage
covachero's Avatar, Join Date: Aug 2007
Newbie Member
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.
jwshepherd's Avatar, Join Date: Aug 2007
Team Leader
sorry try an asterick instead of a percent sign.*
covachero's Avatar, Join Date: Aug 2007
Newbie Member
Thanks a lot, with the * works just great.
jwshepherd's Avatar, Join Date: Aug 2007
Team Leader
no problem