2

コードを使用して、Active Directory からすべてのユーザーを取得しようとしています。

PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password);
UserPrincipal u = new UserPrincipal(ad) {Name = "*"};
PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };
foreach (var principal in search.FindAll()) 
{
    //do something 
}

ただし、最初の 1000 行のみが返されます。DirectorySearcher を使用せずにすべてのユーザーを取得する方法。ありがとう。

4

3 に答える 3

2

DirectorySearcherを使用せずにそれを行うことはできないと思います。

コードスニペット -

// set the PageSize on the underlying DirectorySearcher to get all entries
((DirectorySearcher)search.GetUnderlyingSearcher()).PageSize = 1000;

また、OU に 3000 人のユーザーが含まれている場合、DirectorySearcher を使用してすべてのユーザーを検索する方法を参照してください。

于 2015-11-20T11:24:29.967 に答える
1

基になるものを取得し、そのプロパティDirectorySearcherを設定する必要があります。PageSize

using (PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password))
{ 
    UserPrincipal u = new UserPrincipal(ad) {Name = "*"};

    PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };

    // get the underlying "DirectorySearcher"
    DirectorySearcher ds = search.GetUnderlyingSearcher() as DirectorySearcher;

    if(ds != null)
    {
        // set the PageSize, enabling paged searches
       ds.PageSize = 500;
    }


    foreach (var principal in search.FindAll()) 
    {
        //do something 
    }
}
于 2015-11-20T11:30:57.717 に答える