Today, i will show you Querying Active Directory with LINQ.
Sample Code
var users = new DirectoryObject<User>(new DirectoryEntry("LDAP://localhost"), SearchScope.Subtree);
var groups = new DirectoryObject<Group>(new DirectoryEntry("LDAP://localhost"), SearchScope.Subtree);
// Searching AD User
var results = from user in users
where user.Name == "Farooq Ahmad" || user.Name == "Guest"
select new { user.Name };
//Searching AD Group
var groupResults = from group1 in groups
where group1.Name == "Users" || group1.Name == "IIS_WPG"
orderby group1.Name descending
select group.Name;