【问题标题】:Can I get more than 1000 records from a PrincipalSearcher?我可以从 PrincipalSearcher 获得超过 1000 条记录吗?
【发布时间】:2019-01-08 00:38:17
【问题描述】:

我正在尝试使用代码从 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 的情况下检索所有用户。 谢谢。

【问题讨论】:

    标签: c# active-directory multiple-users


    【解决方案1】:

    我认为如果不使用 DirectorySearcher,您将无法做到这一点。

    代码 sn-p -

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

    另见If an OU contains 3000 users, how to use DirectorySearcher to find all of them?

    【讨论】:

      【解决方案2】:

      你需要获取底层的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 
          }
      }
      

      【讨论】:

        【解决方案3】:

        你可以:

        ((DirectorySearcher)myPrincipalSearcher.GetUnderlyingSearcher()).SizeLimit = 20;
        

        【讨论】:

          猜你喜欢
          • 2010-09-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-30
          • 1970-01-01
          相关资源
          最近更新 更多