If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

Querying Active Directory with LINQ

by Farooq Kaiser 30. May 2009 14:45

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; 

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | API | C#

Comments

Jobs Autos Real estate Videos Power by Google