Use an LDAP OR Filter in a Search

Demonstration script showing the use of an OR filter in a LDAP query.

 
 
 
 
 
5 Star
(1)
Add to favorites
Active Directory
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Searc of a particular Computer in Active Directory
    1 Posts | Last post April 26, 2011
    • Hi,
      
      I need to search a computer by its name in active directory. Although I can search it using sequential search (by searching in each OU), but its taking too much time.
      
      I am using  following code
      
      100    Set oCmd = CreateObject("ADODB.Command")
      104    Set ocon = CreateObject("ADODB.Connection")
      110    ocon.provider = "ADsDSOObject"
      120    ocon.Properties("User ID") = struser
      124    ocon.Properties("Password") = strpassword
      126    ocon.Properties("Encrypt Password") = True
      128    ocon.Properties("ADSI Flag") = 3
      132    ocon.Open = "Active Directory Provider"
      140    oCmd.ActiveConnection = ocon
      142    strQuery = "SELECT distinguishedName FROM 'LDAP://" & strDC & "." & strDomain & "/" & strDOMLD & "' WHERE CN='" & strMachineName & "'"
      148    oCmd.CommandText = strQuery
      156    oCmd.Properties("Searchscope") = 2
      166    oCmd.Properties("Cache Results") = False
      170    Set ors = oCmd.Execute
      
      
      This code is working on one domain. if I do not use the "strDC" variable in above code it give me the error "Table does not exists". 
      
      In another domain its giving me the same error permanently. means current code also not working and i am getting the same error. I need the clarification on below mentioned points.
      
      1. Does it means that Domain controler value for another domain I am using is wrong
      2. Is it necessary to use the domain conroler value to use the ldap search
      3. How can I modify the code provided by you, in order to search the computer by its name