Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit LDAP/ADO search result 1

Status
Not open for further replies.

sunny001

Programmer
Feb 6, 2004
6
AT
I use the following code to get all users in a domain, but I only get 1000 records back. There should be over 3000 in the User folder and some more elsewhere.

Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOOBJECT"
objconn.open
strQuery = &quot;<LDAP://&quot; &strDomain&&quot;>;(&(objectClass=user));ADsPath,givenName;subtree&quot;

Set objRecordSet = objConn.Execute(strQuery)
i=0
objrecordset.movefirst
While Not objRecordSet.EOF
i=i+1
objRecordSet.MoveNext
Wend
msgbox i

Where is the error?
 
Try adding this
ObjConn.Properties.Item(&quot;Page size&quot;).Value = 250 'This is done to allow more than 1000 records in the recordset
 
Thanks, I have changed it a bit and now it works (properties for command object, not connection):

Set oConnection = CreateObject(&quot;ADODB.Connection&quot;)
Set oCommand = CreateObject(&quot;ADODB.Command&quot;)
oConnection.Provider = &quot;ADsDSOOBject&quot;
oConnection.Open &quot;Active Directory Provider&quot;
Set oCommand.ActiveConnection = oConnection

strDomain = &quot;xyz&quot;
sFilter = &quot;(&(ObjectCategory=person)(ObjectClass=user))&quot;
sQuery = &quot;<LDAP://&quot; &strDomain&&quot;>;&quot;&sfilter&&quot;;ADsPath,givenName;subtree&quot;

oCommand.CommandText = sQuery
oCommand.Properties(&quot;Page Size&quot;) = 10000
oCommand.Properties(&quot;Timeout&quot;) = 30
oCommand.Properties(&quot;Cache Results&quot;) = False

Set oResults = oCommand.Execute
i=0
Do Until oResults.EOF
i=i+1
oResults.MoveNext
Loop
msgbox i
 
Aye, sorry, I was in a hurry, and I perform my query using a SQL style command so I confused myself looking at yours..


Sub GetUsers(LDAPPath)
'Open a Connection object
Dim x
Dim Con,Com,Rs
Set con = CreateObject(&quot;ADODB.Connection&quot;)
con.Provider = &quot;ADsDSOObject&quot;
con.Open &quot;Active Directory Provider&quot;
'Create a command object on this connection
Set Com = CreateObject(&quot;ADODB.Command&quot;)
Set Com.ActiveConnection = con
Com.Properties.Item(&quot;Page size&quot;).Value = 250 'This is done to allow more than 1000 records in the recordset
Com.CommandText = &quot;select adspath,samaccountname,name,modifytimestamp from '&quot; & LdapPath & &quot;' where objectCategory='User' ORDER BY samaccountname&quot;
Set rs = Com.Execute
'--------------------------------------
' Navigate the record set
'----------------------------------------
While Not rs.EOF
DisplayInfo=Rs.Fields(&quot;name&quot;) &&quot;,&quot; & Rs.Fields(&quot;samaccountname&quot;) &&quot;,&quot; & Rs.Fields(&quot;modifytimestamp&quot;)
Wscript.Echo DisplayInfo
'WriteFile FilePath,DisplayInfo,ForAppending
rs.MoveNext
Wend
con.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top