Posted By

lance on 02/03/11


Tagged

ldap


Versions (?)

LDAP query to find all users without an entry in the webpage field in Active Directory


 / Published in: Visual Basic
 

  1. Set oRootDSE = GetObject("LDAP://RootDSE")
  2. Set Conn = CreateObject("ADODB.Connection")
  3. Set Comm = CreateObject("ADODB.Command")
  4. Conn.Provider = "ADsDSOObject"
  5. Conn.Open "Active Directory Provider"
  6. Set Comm.ActiveConnection = Conn
  7. Comm.Properties("Page Size") = 1000
  8.  
  9. strBase = "<LDAP://" & oRootDSE.get("defaultNamingContext") & ">;"
  10. strFilter = "(&(objectCategory=person)(objectclass=user)(objectCategory=person)(!wwwhomepage=*));"
  11. strAttrs = "givenName,sn;"
  12. strScope = "subtree"
  13.  
  14. Comm.CommandText = strBase & strFilter & strAttrs & strScope
  15. Set RS = Comm.Execute
  16.  
  17. If NOT RS.EOF Then
  18.  
  19. Set fso = CreateObject("Scripting.FileSystemObject")
  20. Set MyFile = fso.CreateTextFile("c:\noids.txt", true)
  21.  
  22. RS.MoveFirst
  23. MyFile.WriteLine("First Name,Last Name")
  24. Do Until RS.EOF
  25. 'WScript.Echo Rs.Fields(0) & "," & RS.Fields(1)
  26. MyFile.WriteLine(Rs.Fields(0) & "," & RS.Fields(1))
  27. RS.MoveNext
  28. Loop
  29. End If
  30. Conn.Close
  31. MyFile.Close
  32.  
  33. Set oRootDSE = Nothing
  34. Set Conn = Nothing
  35. Set Comm = Nothing
  36. Set User = Nothing
  37. Set fso = Nothing

Report this snippet  

You need to login to post a comment.