我想訪問使用LINQ到LDAP的ActiveDirectory,我想要獲得該列表中的所有用戶
我該怎麼做?如何獲取使用LINQ to LDAP的活動目錄中的用戶列表?
回答
你可以嘗試下面的東西。
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; }
}
使用此代碼從一個控制檯應用程序訪問廣告,讓廣告服務器在下面的代碼:
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;
}
欲瞭解更多信息,請查看Get All Users using C# with Linq To Active Directory
對於獲得有關此主題檢查的全面知識(Almost) Everything In Active Directory via C#
我希望這對你有幫助。
非常感謝我的朋友,這很好,我還有一個問題:你的代碼在AD服務器上運行,我可以在另一臺計算機(加入域的計算機)上運行這個應用程序在這種情況下,LDAP地址是什麼? –
@SirwanAfifi很高興聽到它的幫助。對於你的問題,你可以參考這篇文章http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C – Sampath
@Sampath你會推薦使用LINQ到LDAP嗎? –
- 1. 如何從MVC中的活動目錄獲取用戶列表?
- 2. 如何獲取在LDAP活動目錄中被禁用的用戶
- 3. 從活動目錄獲取當前登錄用戶的列表
- 4. 如何從活動目錄獲取用戶列表?
- 5. 如何使用Powershell獲取活動目錄中的非活動用戶?
- 6. 我如何獲得使用.NET的活動目錄中的用戶列表?
- 7. 如何使用python-ldap讀取活動目錄的內容?
- 8. 如何使用LINQ獲取列表中的下一個活動項目
- 9. 使用PLSQL獲取LDAP用戶列表
- 10. 如何獲取活動目錄查詢中的用戶組?
- 11. 使用ID從LDAP活動目錄獲取數據?
- 12. 如何獲取ldap的SSL證書/活動目錄
- 13. 如何獲取活動目錄用戶的IADs界面?
- 14. 如何使用PHP獲取活動目錄中的部門列表?
- 15. 如何使用C#獲取活動目錄中的部門列表
- 16. 通過ldap獲取活動目錄中不同的城市列表
- 17. 如何獲取活動目錄用戶的「ntSecurityDescriptor」對象
- 18. 如何從Jxplorer獲取活動目錄用戶的UID
- 19. 從活動目錄中獲取任何用戶的類型
- 20. LDAP:如何使用C#從特定組獲取用戶列表?
- 21. 如何使用Linq獲取列表中項目的摘要
- 22. 如何在Python中使用Wmi從活動目錄獲取計算機列表
- 23. 從活動目錄中提取用戶列表
- 24. 如何獲得使用Linq to SQL的列名稱列表
- 25. 活動目錄和LDAP庫
- 26. 如何從活動目錄中使用c#獲取SID-History值
- 27. 如何使用目錄服務LDAP獲取用戶所屬的所有組?
- 28. 從活動目錄中獲取任何用戶的用戶名和暱稱
- 29. 如何獲取我的FullText目錄中使用的StopWords列表?
- 30. 如何獲得使用PHP的活動用戶列表?
我在我的文章中包含了與此主題相關的非常有用的鏈接。請檢查一下。 – Sampath