我需要能够识别我的 AD (Active Directory) 域中的所有用户.我有域名,仅此而已.如果我可以将它作为 UserPrincipal 或其他东西的列表来获取它会很震撼,但如果它只是一个字符串,那么我可以从那里获取我需要的其余信息.
I have a need to be able to identify all of the users on my AD (Active Directory) domain. I have the domain name and that is about it. It would rock if i could get it as a list of UserPrincipal or something but if its just a string then i can get the rest of the info i need from there.
谢谢!
如果你只需要获取用户列表你可以使用这个代码 -
If you just have to get the users list you can use this code -
var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com"));
var searcher = new DirectorySearcher(dirEntry)
{
Filter = "(&(&(objectClass=user)(objectClass=person)))"
};
var resultCollection = searcher.FindAll();
但是,如果您需要对 AD 进行更多操作,则应考虑使用 LINQ to AD API http://linqtoad.codeplex.com/
However if you have to more operations with AD you should consider using LINQ to AD API http://linqtoad.codeplex.com/
它是一个基于 Linq 的 API,用于处理 AD.易于使用,我用它取得了一些不错的结果.
It is a Linq based API to work with AD. Easy to use and I have got some good results with it.
这篇关于从 AD 域中获取所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么我不应该总是在 C# 中使用可空类型Why shouldn#39;t I always use nullable types in C#(为什么我不应该总是在 C# 中使用可空类型)
C# HasValue vs !=nullC# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET:空值和 DbNull —— 有没有更高效的语法C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有没有更高效的语法?)
如何在c#中将空值设置为int?How to set null value to int in c#?(如何在c#中将空值设置为int?)
使用 Min 或 Max 时如何处理 LINQ 中的空值?How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 时如何处理 LINQ 中的空值?)
在 C# 中如果不为 null 的方法调用Method call if not null in C#(在 C# 中如果不为 null 的方法调用)