关于.net:使用” SQL”查询Active Directory?

关于.net:使用” SQL”查询Active Directory?

Querying Active Directory with “SQL”?

我只是想知道是否有人知道Active Directory或对其进行包装以便能够在.net中轻松查询它?类似于" LINQ-to-ActiveDirectory"或某些SQL方言,即能够执行"从/ Users / SomeOU / AnotherOU选择SELECT DISTINCT(DEPARTMENT)"或"从域选择SELECT用户"等操作。

据我所知,可以以" SQLesque"方式查询WMI和IIS,我只是想知道对于Active Directory是否也可以进行类似的操作,而不必学习另一种查询语言(LDAP)?


LINQ to Active Directory implements a
custom LINQ query provider that allows
querying objects in Active Directory.
Internally, queries are translated
into LDAP filters which are sent to
the server using the
System.DirectoryServices .NET
Framework library.

http://www.codeplex.com/LINQtoAD

样本(来自站点):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// NOTE: Entity type definition"User" omitted in sample - see samples in release.

var users = new DirectorySource<User>(ROOT, SearchScope.Subtree);
users.Log = Console.Out;

var res = from usr in users
          where usr.FirstName.StartsWith("B") && usr.Office =="2525"
          select new { Name = usr.FirstName +"" + usr.LastName, usr.Office, usr.LogonCount };

foreach (var u in res)
{
    Console.WriteLine(u);
    u.Office ="5252";
    u.SetPassword(pwd);
}

users.Update();


推荐阅读