怎样才能使用LINQ to LDAP在Active Directory用户的列表? [英] how can get List of users in active directory using LINQ to LDAP?
问题描述
我想使用LINQ to LDAP访问成ActiveDirectory,我想在结果
的所有用户的名单我该怎么办呢?
I want to access to ActiveDirectory using LINQ to LDAP and I want to Get List of All users in that
how can I do that?
推荐答案
您可以尝试像下面
using ActiveDs;
using BdsSoft.DirectoryServices.Linq;
using System.Linq.Expressions;
using System.DirectoryServices;
[DirectorySchema( "user", typeof( IADsUser ) )]
class User
{
public string Name { get; set; }
public string sAMAccountName { get; set; }
public string objectCategory { get; set; }
public string mail { get; set; }
public string Description { get; set; }
[DirectoryAttribute( "PasswordLastChanged", DirectoryAttributeType.ActiveDs )]
public DateTime PasswordLastSet { get; set; }
[DirectoryAttribute("distinguishedName")]
public string Dn { get; set; }
[DirectoryAttribute("memberOf")]
public string[] Groups { get; set; }
}
使用此代码从一个控制台应用程序访问AD,把你的AD服务器在下面的代码:
Use this code to access AD from a console app, placing your AD server in the below code:
static void Main( string[] args )
{
IEnumerable<User> users = GetADUsers();
Console.WriteLine( "Users: " + users.Count().ToString() );
}
static DirectoryEntry ROOT = new DirectoryEntry( "LDAP://MyADDomainLocation.com" );
private static IEnumerable<User> GetADUsers()
{
IEnumerable<User> users;
var usersDS = new DirectorySource<User>( ROOT, SearchScope.Subtree );
users = from usr in usersDS
where usr.Name == "A*" // FIlter A then any character(s)
select usr;
users = users.OrderBy( user => user.Name ).ToList(); // Sort them alphabetically by name.
return users;
}
有关详细信息,检查的 获取所有使用C#的LINQ到Active Directory <用户/ STRONG>
For more information check Get All Users using C# with Linq To Active Directory
和< A HREF =http://linqtoldap.codeplex.com/相对=nofollow> LINQ到LDAP
如需获取有关此主题的检查 <通过C#STRONG>(几乎)一切在Active Directory中
For get comprehensive knowledge about this subject check (Almost) Everything In Active Directory via C#
我希望这会帮助你。
这篇关于怎样才能使用LINQ to LDAP在Active Directory用户的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!