Connecting Active Directory

Active Directory - AD
Paramters for connecting the AD

Domain name :domain1
Service Account :the Account available in the AD server authenticated to connect AD
Password : Password for that service account

DirectoryEntry object is used for connecting the AD.
DirectorySearcher object is used for fetching the entry from the AD.

DirectoryEntry objDirectoryEntry = new DirectoryEntry(adConnectionString, Domain name + "\\" + ServiceAccount, Password, AuthenticationTypes.Secure);
DirectorySearcher objDirectorySearcher = new DirectorySearcher(objDirectoryEntry);
SearchResult objSearchResult;

The below code will be used to filter and fetch the data from the AD.Thje filter will be used to filter the specific Organizational Unit, or a specific User, or a group
We can fetch all the data in a method FindAll.We can also fetch the indivdual user using another method called FindOne of the DirectorySearcher object.
The results fetched are assigned to another object called searchresult.
This will return null if we are not able to fetch data from the AD

objDirectorySearcher.PageSize = 1;
objDirectorySearcher.Filter = "(objectClass=*)";
objSearchResult = objDirectorySearcher.FindAll();
if (objSearchResult != null)



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: