Find all users (VBScript)

This code can be found in Chapter 6 of Active Directory Cookbook, 2nd 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.

' This VBScript code finds all user accounts in a domain.

' ---------------------------------------------------------------
' Provided as a web-only addition for the book:
'     "Active Directory Cookbook" by Robbie Allen
' ISBN: 0-596-00466-4
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strDomainDN = "<DomainDN>"    ' e.g. dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------

strBase   =  "<LDAP://" & strDomainDN & ">;"
' To search the whole forest using the global catalog, uncomment the following line:
' strBase   =  "<GC://" & strDomainDN & ">;"

strFilter = "(&(objectclass=user)(objectcategory=person));" 
strAttrs  = "name;"
strScope  = "subtree"

set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
objRS.MoveFirst
while Not objRS.EOF
    Wscript.Echo objRS.Fields(0).Value
    objRS.MoveNext
wend

This code has been viewed 14823 times.

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