Dharmarajan

Dharmarajan

  • NA
  • 10
  • 3.4k

Active directory code

Dec 21 2009 1:34 AM
Hi,

This the code i wrote to extract all the users details of an organization across domain

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher("gc://dc=xxxdomain,dc=net");
mySearcher.Filter = ("(objectCategory=person)");
mySearcher.PageSize = int.MaxValue;
Console.WriteLine("Listing of users in the Active Directory");
Console.WriteLine("========================================");

using (var searchResultCollection = mySearcher.FindAll())
{
foreach (System.DirectoryServices.SearchResult searchResult in searchResultCollection)
{
foreach (string prop in searchResult.Properties["distinguishedname"])
{
Console.WriteLine("distinguishedname : " + prop.Trim());
break;
}
}
}


I got some output that only fetches the data for a particular domain (eg: APJ or NA or EMEA) where the user is accessing the application and not the complete data. Can anyone help me on this what went wrong in the code?

Answers (2)