.net – 用“SQL”查询Active Directory?

前端之家收集整理的这篇文章主要介绍了.net – 用“SQL”查询Active Directory?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是想知道是否有人知道或制作了一个围绕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();
原文链接:https://www.f2er.com/mssql/75651.html

猜你在找的MsSQL相关文章