I want to query Active Directory using VBScript (classic ASP). How can I accomplish that?
A:
Shoban
2009-07-07 04:22:55
+2
A:
To look at all the members of an OU, try this...
Set objOU = GetObject("LDAP://OU=YourOU,DC=YourDomain,DC=com")
For each objMember in ObjOU ' get all the members'
' do something'
Next
To do a custom search for DNs try this...
set conn = createobject("ADODB.Connection")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
strQueryDL = "<LDAP://" & strDefaultNamingContext & ">;(&(objectCategory=person)(objectClass=user));distinguishedName,adspath;subtree"
set objCmd = createobject("ADODB.Command")
objCmd.ActiveConnection = Conn
objCmd.Properties("SearchScope") = 2 ' we want to search everything
objCmd.Properties("Page Size") = 500 ' and we want our records in lots of 500
objCmd.CommandText = strQueryDL
Set objRs = objCmd.Execute
While Not objRS.eof
' do something with objRS.Fields("distinguishedName")'
objRS.MoveNext
Wend
Ken Hughes
2009-07-07 12:27:25
2009-07-07 18:53:27
A better way would be to actually use the particular firstname/lastname you are looking for in the query...strQueryDL = "<LDAP://" (distinguishedName,adspath;subtree"...' do something with objRS.Fields("sAMAccountName")'
Ken Hughes
2009-07-16 01:29:16
A:
You want to use Active Directory Service Interfaces (ADSI)
The ADSI Scripting Primer is a good place to start learning and find examples. (btw, these links refer to Windows 2000, but are valid for subsequent versions of Windows as well).
Jay
2010-08-21 19:54:59