我只是想知道是否有人知道或制作了一个围绕Active Directory的包装器,以便能够在.net中轻松查询它?有点像“LINQ-to-ActiveDirectory”或一些sql方言,即能够做“SELECT DISTINCT(DEPARTMENT)FROM / Users / SomeOU / AnotherOU”或“SELECT user FROM domain”等等.
据我所知,有可能以“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
样本(来自网站):
// 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();