Simple Search (VBScript)

This code can be found in Chapter 22 of Active Directory, 3rd Edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Active Directory, Third Edition" 
' ISBN: 0-596-10173-2

Option Explicit

Const adStateOpen = 1

Dim objConn  'ADO Connection object
Dim objRS    'ADO Recordset object

Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADSDSOObject"
objConn.Open "","CN=Administrator,CN=Users,dc=mycorp,dc=com", "mypass"
If objConn.State = adStateOpen Then
  WScript.Echo "Authentication Successful!"
Else
  WScript.Echo "Authentication Failed."
  WScript.Quit(1)
End If
   
Set objRS = objConn.Execute _
  ("<LDAP://dc=mycorp,dc=com>;(&(objectCategory=person)" _
  & "(objectClass=user));Name,ADsPath;SubTree")
   
While Not objRS.EOF
  Wscript.Echo objRS.Fields.Item("Name").Value _
    & vbCrLf & objRS.Fields.Item("ADsPath").Value
  objRS.MoveNext
Wend
   
Set objRS = Nothing
objConn.Close

This code has been viewed 3092 times.

New from the creators of TechTasks.com: StatSheet.com