久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果一個OU包含3000個用戶,如何使用DirectorySear

If an OU contains 3000 users, how to use DirectorySearcher to find all of them?(如果一個OU包含3000個用戶,如何使用DirectorySearcher查找所有用戶?)
本文介紹了如果一個OU包含3000個用戶,如何使用DirectorySearcher查找所有用戶?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

I use this code:

DirectoryEntry objEntry;
DirectorySearcher objSearchEntry;
SearchResultCollection objSearchResult;
string strFilter = "(&(objectCategory=User))";
objEntry = new DirectoryEntry(conOUPath, conUser, conPwd, AuthenticationTypes.Secure);
objEntry.RefreshCache();
objSearchEntry = new DirectorySearcher(objEntry);
objSearchEntry.Filter=strFilter;
objSearchEntry.SearchScope=SearchScope.Subtree;
objSearchEntry.CacheResults=false;
objSearchResult=objSearchEntry.FindAll();

Each time, it only return 1000 users, but there are 3000 users in that OU.

How can i find all of them ?

解決方案

If you're on .NET 3.5 or newer, you should check out the PrincipalSearcher and a "query-by-example" principal to do your searching:

// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN", "OU=SomeOU,DC=YourCompany,DC=com");

// define a "query-by-example" principal - here, we search for a UserPrincipal 
// and with the first name (GivenName) of "Bruce"
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = "Bruce";

// create your principal searcher passing in the QBE principal    
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);

// set the PageSize on the underlying DirectorySearcher to get all 3000 entries
((DirectorySearcher)srch.GetUnderlyingSearcher()).PageSize = 500;

// find all matches
foreach(var found in srch.FindAll())
{
    // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
}

If you haven't already - absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in System.DirectoryServices.AccountManagement

Update:

Of course, depending on your need, you might want to specify other properties on that "query-by-example" user principal you create:

  • Surname (or last name)
  • DisplayName (typically: first name + space + last name)
  • SAM Account Name - your Windows/AD account name
  • User Principal Name - your "username@yourcompany.com" style name

You can specify any of the properties on the UserPrincipal and use those as "query-by-example" for your PrincipalSearcher.

Update #2: If you want to search just inside a given OU, you can define that OU in the constructor of the PrincipalContext.

這篇關于如果一個OU包含3000個用戶,如何使用DirectorySearcher查找所有用戶?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 日韩久久网 | 国产中文字幕一区 | 一级免费片 | 国产高清免费 | 黄色大片免费在线观看 | 欧美一级日韩一级 | 亚洲欧美日韩一区二区三区四区 | 国产乱码精品一区二区三 | 久久综合热| 日韩成人高清 | 欧美日韩无 | 亚洲综合二区 | 熟女毛片 | 精品在线免费视频 | 美日韩一区 | 成人欧美一区二区三区白人 | 久久久久久亚洲精品 | 亚洲在线视频观看 | 亚洲一区二区免费 | 亚洲国产精品久久久久 | 三级理论片 | 九九久久久 | 午夜视频| 亚洲欧美视频一区 | 亚洲黄色片 | 国产精品久久久久久久久久久久久 | 色黄大色黄女片免费中国 | 成人免费片| 日韩黄色录像 | 日韩精品成人免费观看视频 | 精品久久久久久久久久久久久 | 日韩中文字幕一区二区三区 | 国产精品久久久一区二区三区 | 国产福利91| 成人免费黄色大片 | 欧美亚洲国产精品 | 好好的日com | 日本一级淫片 | 一级黄色网 | 毛片网站在线播放 | 91福利在线视频 |