获得从AD域中的所有用户用户、AD

2023-09-03 01:45:06 作者:遍体鳞痛つ殇

我有一个需要能够识别的所有用户对我的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.

谢谢!

推荐答案

如果你只需要获得用户列表,你可以使用这个code -

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 /

这是一个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.