Skip to content

IAdmSearchResultIterator2

The IAdmSearchResultIterator2 interface allows retrieving search results in pages instead of retrieving them one by one.

Inheritance: The IAdmSearchResultIterator2 interface inherits from the IAdmSearchResultIterator interface.

Methods

Details

GetNextPage()

Gets the next page of search results. The number of search results per page is determined by the SearchParameters::PageSize property.

AdmSearchResult[] GetNextPage()

Examples

The following code sample outputs names and the total count of contacts located in an Organizational Unit.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$ouDN = "OU=Contacts,DC=domain,DC=com"

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the Organizational Unit
$searcher = $admService.OpenObject("Adaxes://$ouDN", $NULL, $NULL, 0)

# Specify search parameters
$searcher.SearchFilter = "(objectClass=contact)"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500 # search results per page

try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()

    $totalCount = 0
    while($True)
    {
        # Get the next page of search results
        $searchResults = $searchResultIterator.GetNextPage()
        if (($searchResults.Length -eq 0) -and ($searchResultIterator.IsSearchCompleted))
        {
            break # no more results to return
        }

        $totalCount += $searchResults.Length
        foreach ($searchResult in $searchResults)
        {
            Write-Host $searchResult.Name
        }

        Start-Sleep -Milliseconds 0
    }

    Write-Host
    Write-Host "Contacts found: $totalCount"
}
finally
{
    # Release resources used by the search
    $searchResultIterator.Dispose()
}
using System;
using System.Threading;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
        const String ouPath = "Adaxes://OU=Contacts,DC=domain,DC=com";

        // Connect to the Adaxes service
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to the Organizational Unit
        IAdmDirectorySearcher searcher = (IAdmDirectorySearcher)admService.OpenObject(
            ouPath, null, null, 0);

        // Specify search parameters
        searcher.SearchFilter = "(objectClass=contact)";
        searcher.SearchScope = ADS_SCOPEENUM.ADS_SCOPE_SUBTREE;
        searcher.PageSize = 500; // search results per page

        // Execute search
        using (IAdmSearchResultIterator2 searchResultIterator =
                (IAdmSearchResultIterator2)searcher.ExecuteSearch())
        {
            int totalCount = 0;
            while (true)
            {
                // Get the next page of search results
                AdmSearchResult[] searchResults = searchResultIterator.GetNextPage();
                if ((searchResults.Length == 0) && (searchResultIterator.IsSearchCompleted))
                {
                    break; // no more results to return
                }

                totalCount += searchResults.Length;
                foreach (AdmSearchResult searchResult in searchResults)
                {
                    Console.WriteLine(searchResult.Name);
                }

                Thread.Sleep(0);
            }

            Console.WriteLine();
            Console.WriteLine("Contacts found: " + totalCount);
        }
    }
}

Requirements

Minimum required version: 2017.1

See also