我只是想知道是否有人知道Active Directory或对其进行包装,以便能够在.net中轻松查询它?类似于“LINQ to ActiveDirectory”或某些SQL方言,即能够执行“从/Users/SomeOU/AnotherOU选择SELECT DISTINCT(部门)”或“从域中选择用户”等操作。
据我所知,可以以“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();
关于.net - 使用 “SQL”查询Active Directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/90812/