Reputation: 2388
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.
Upvotes: 1
Views: 1443
Reputation: 754568
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...
Upvotes: 0