I could not find an example of an ADSI API paged search, and learned the following through trial-and-error (using VB.NET). LDAP searches are limited to 1000 results per 'page', use multiple pages to get all results. Please comment if you can improve.
Dim strUserName, strPwd as string
Dim intPageSize as integer
Dim dtUser as dataTable
Dim drUser as dataRow
Dim adsNamespace As AdmNamespace = New AdmNamespace()
Dim admService As IAdmService = adsNamespace.GetNearestService("d2.waukco.gov"), strUserName, strPwd)
Dim admDirectorySearcher As IAdmDirectorySearcher = CType( admService.OpenObject(
"Adaxes://OU=UserAccounts,DC=d2,DC=waukco,DC=gov", strUserName, strPwd, 0),
IAdmDirectorySearcher)
admDirectorySearcher.SearchFilter = "(&(objectCategory=person)(objectClass=user))"
admDirectorySearcher.SetPropertiesToLoad(New String() {"department", "cn"})
admDirectorySearcher.PagingInfo = New AdmSearchPagingInfo(1, intPageSize)
admDirectorySearcher.ReferralChasing = ADS_CHASE_REFERRALS_ENUM.ADS_CHASE_REFERRALS_NEVER
{ define datatable dtUser}
Dim admSearchResultIterator As IAdmSearchResultIterator
Try
While True
admSearchResultIterator = admDirectorySearcher.ExecuteSearch()
If admSearchResultIterator.Count = 0 Then Exit While
For Each admSearchResult As AdmSearchResult In admSearchResultIterator.FetchAll()
drUser = dtUser.NewRow
drUser("department") = admSearchResult.Properties( "department").Value.ToString
drUser("cn") = admSearchResult.Properties( "cn").Value.ToString
dtUser.Rows.Add(drUser)
Next
admDirectorySearcher.PagingInfo = New AdmSearchPagingInfo(
admSearchResultIterator.ResultPagingInfo.Offset + intPageSize,
intPageSize, admSearchResultIterator.ResultPagingInfo.GetCookie)
End While
Catch ex As Exception
Dim strErr As String = ex.Message
Finally
If Not IsNothing(admSearchResultIterator) Then admSearchResultIterator.Dispose()
End Try