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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LDAP Query only returning 1000

Status
Not open for further replies.
Aug 9, 2002
9
GB
Afternoon All,

I'm fairly sure I'm being a bit daft about this one but I'm stumped so here we go.

I've got a script which we use to pull out lists of members of AD Groups. The problem is that we have some groups which have more than 1000 users in them and these are being truncated to only display 1000 users.

The code for this part of the script is
---------
do while oRS.EOF <> True

dim i

LeftGroup = Left(oRS.Fields("cn"), len(Match))

If Ucase(LeftGroup) = UCase(Match) Then
Set Group = GetObject("LDAP://CN=" & oRS.Fields("cn") & ", " & ADLocn)
WScript.Echo "LDAP://CN=" & oRS.Fields("cn") & ", " & ADLocn
For Each Item in Group.Member
i= i+1
Set User = GetObject("LDAP://" & item)
Name1 = Split(User.userPrincipalName, "@")
Name2 = Name1(0) & ";"
Output.WriteLine Name2
WScript.Echo Name2

Next

wscript.echo "i IS : " & i
End If

oRS.MoveNext

Loop
------------

I know that using RecordSets you can get back more than 1000 results, but how do I get the Group.Member bit to show all the results?

Is it possible to use a SQL command to get this back, in which case I could use a RecordSet and I'd be sorted?

Any help would be greatly appreciated.

Thanks

Gareth
 
i think it is something to do with the LDAP provider you are using.
by default when i guery ad and get a RS back i only get 1000 records unless i tell it otherwise.

i would try using the WinNT provider instead

GetOBject("WinNT://" & domain & "/" & groupname & ",group")

i think this might work.

if not, (i know its not as efficient) but you could bind to each user object and build your own collect/array/dictionary of group & user,,,silly suggestion perhaps
 
I'd use the ADODB method of getting to the data. I routinely have to query on 50000+ objects. By adding the "Size Limit" property, I'm able to query all objects and get the full return.

Const ADS_SCOPE_SUBTREE = 8

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection

objCommand.CommandText = _
"SELECT member " _
& "FROM 'LDAP://DC=mycompany,DC=com' " _
& "WHERE objectCategory='group' AND cn='mygroup'"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 300
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
objCommand.Properties("Size Limit") = 75000

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
arrMemberOf = objRecordSet.Fields("member").Value
For Each strMember in arrMemberOf
Set User = GetObject("LDAP://" & strMember)
Name1 = Split(User.userPrincipalName, "@")
Name2 = Name1(0) & ";"
WScript.Echo Name2
Next
objRecordSet.MoveNext
Loop

WScript.Quit

 
CmdrKitsune, that's almost exactly what it says in the Microsoft column I referenced above, except they say that the magic is in specifying Page Size rather than Size Limit (since the size is able to be unlimited
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top