VBScript AD Select all users beginning with!!!

Discussion in 'Visual Basic ( VB )' started by covachero, Aug 6, 2007.

  1. covachero

    covachero New Member

    Joined:
    Aug 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Aug 6, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not a LDAP SQL expert but you can refer to the LIKE operator which we have.

    Code:
    ....  WHERE sAMAccountName LIKE 'A%'
     
  3. covachero

    covachero New Member

    Joined:
    Aug 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  4. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    http://www.officialhackers.com
    Try
    Code:
    ....WHERE sAMAccountName LIKE 'A%'
    instead of percentage
     
  5. covachero

    covachero New Member

    Joined:
    Aug 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Don't understando (Instead of percentage) what I'm suppose to use instead of percentage?

    Thank you for your repply.
     
  6. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    http://www.officialhackers.com
    sorry try an asterick instead of a percent sign.*
     
  7. covachero

    covachero New Member

    Joined:
    Aug 6, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Thanks a lot, with the * works just great.
     
  8. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    http://www.officialhackers.com

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice