반응형
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.
반응형
'.Net' 카테고리의 다른 글
The underlying connection was closed – REST API call over HTTPS (0) | 2020.11.04 |
---|---|
.Net for Apache Spark 1.0 공개 (0) | 2020.11.01 |
.Net core에서 .Net 5로 변화, Core, Framework 통합 (0) | 2020.10.30 |
C# - DllImport – Using the C ++ DLL / Windows API (0) | 2020.10.29 |
MVC - submit change or clear value of Textbox what else (0) | 2020.10.28 |