1

does anyone know of any strongly typed language for building LDAP queries in C#? I'd like to move away from

(&(|(objectClass=user)(objectClass=group)(objectClass=computer)(objectClass=contact))((objectGUID={0})))

and preferably have a fluid api for building logical queries.

MichaC
  • 13,104
  • 2
  • 44
  • 56
hoetz
  • 2,368
  • 4
  • 26
  • 58

3 Answers3

3

Well you can try Linq to LDAP

here you have a tutorial

Frederiek
  • 1,605
  • 2
  • 17
  • 32
  • That looks awesome, why didn't I find this earlier!? – hoetz Oct 19 '11 at 08:23
  • After a quick glance it has one limitation, though: You can only build queries for ONE object type i.e. user. Searching over Users OR groups OR computers seems impossible, let's see if we can hack this in... – hoetz Oct 19 '11 at 09:49
0

http://linqtoad.codeplex.com/ is a good one

Matt
  • 6,787
  • 11
  • 65
  • 112
  • 3
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Bucket Nov 26 '13 at 21:17
  • @DesertIvy, Normally I would agree with you, but this is not some random link to some article - it is the home page of a project on codeplex. – Matt Nov 28 '13 at 13:17
0

If you're on .NET 3.5 and up, you can also check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace.

Read all about it here:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}

The new S.DS.AM makes it really easy to play around with users and groups in AD! Much easier than the earlier DirectoryEntry approach...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459