.Net
C# - DirectorySearcher search result more than 1000
올엠
2020. 11. 1. 18:59
반응형
When searching Active directory, DirectorySearcher will be used to retrieve information from Active Directory.
Below is the code that gets the username information.
string DomainPath = "LDAP://DC=domain,DC=com";
DirectoryEntry searchRoot = new DirectoryEntry(DomainPath);
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
search.PropertiesToLoad.Add("samaccountname");
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
foreach(SearchResult item in resultCol )
{
string username = item.Properties.Contains("samaccountname");
Console.WriteLine(username);
}
However, by default, only 1000 can be viewed.
To do this, you can use the property PageSize in DirectorySearcher.
It can be used as follows.
DirectoryEntry searchRoot = new DirectoryEntry(DomainPath);
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.PageSize = 4000;
It is possible to input up to 32 bits INT size, but please input the appropriate number.
반응형