ADSI scripting information

Connect to RootDSE

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set objCmd = CreateObject("ADODB.Command")
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
objCmd.ActiveConnection = objConn

' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on group objects.
strFilter = "(objectCategory=group)"

' Comma delimited list of attribute values to retrieve.
' The member attribute of group objects is a multi-valued attribute.
strAttributes = "distinguishedName,member"

' Construct the ADO query, using LDAP syntax.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
objCmd.CommandText = strQuery
objCmd.Properties("Page Size") = 100
objCmd.Properties("Timeout") = 30
objCmd.Properties("Cache Results") = False
Set objRs = objCmd.Execute

' Enumerate the recordset Do Until objRs.EOF
strDN = objRs.Fields("distinguishedName").Value
objRs.MoveNext
Loop
objRs.Close