Ldapsearch

In Linux computing, the ldapsearch utility tool comes with the OpenLDAP library and allows a command-line user to run queries against LDAP directories.

Ranged queries

Active Directory sets a limit to the number of results it can return. So a list of employees, for example, may not return the full list.

The following example shows how to use a "ranged query" to specify a range to return:

/usr/local/openldap/bin/ldapsearch -w "password" -D "domain\employee" -h hostname -b "DC=domain,DC=com" "distinguishedname=OU=GroupName,DC=domain,DC=com" "member;range=0-1499" | sed 'N;s/\n //g;P;D;'

The query never returns an indication of the total number of results found, so in order to iterate over an entire array one would need to follow an algorithm such as:

search for 0-1499. If you have all the result then it will return a result set like

member;0-* CN....

If still more rows exist as yet unfetched then the result-set will look like:

member:0-1499.

So to iterate over the whole set, one keeps adding ranges until an asterisk ("*") appears in the result-set.

it:Ldapsearch