Friday, 20 December 2013

Read from Active Directory/AD Groups using C# (.NET Framework 3.5 or newer)

Below is the method I used to search a name from the AD. In my code user can enter the name they want to search in AD and bring the results to a drop down list.


 Search name can also be the first name, last name, username or full name. Therefore this can be changed as one of below;

 




A name can be searched in AD Groups. I have used the domain user name (SamAccountName) to identify a name in AD group which is unique and more accurate. Since I had to bring up search results as user's full name (Display name) ":" domain user name format, I then had to filter out the domain user name into a string variable as below. (Get the names after ":" character).


 To search in AD groups FindByIdentity has been used as below;


No comments:

Post a Comment