久久久久久久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查找所有用戶?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

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.

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

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

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 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#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 97人人草| 久久久久久www | 99久久99久久精品国产片果冰 | 国产成人99av超碰超爽 | 日韩欧美久久精品 | 看亚洲a级一级毛片 | 精品国产一区二区三区久久狼黑人 | 日韩国产在线观看 | 一级片在线观看 | 欧美激情在线播放 | 国产精品亚洲一区二区三区在线 | 国产有码| 日韩精品一区二区久久 | 亚洲国产成人一区二区 | 久久国产精品首页 | 国产精品久久久久久婷婷天堂 | 看一级毛片视频 | 久久婷婷色 | 成人在线视 | 天天躁日日躁狠狠很躁 | 亚洲精品久久久久久首妖 | 91精品国产91久久久久久 | 欧美精品导航 | 亚洲视频在线观看 | 亚洲一区二区综合 | 国产精品久久久久aaaa九色 | 色播久久 | 麻豆一区二区三区精品视频 | 国产一区久久精品 | 亚洲视频二区 | 日本精品免费在线观看 | 中文字幕国产 | 久久久久亚洲精品 | 精品一区二区三区四区 | 午夜精品一区 | 日本爱爱视频 | 欧美精品一区三区 | 伊人伊成久久人综合网站 | 国产精品久久在线 | 国产色播av在线 | 亚洲第一天堂无码专区 |