在 LDAP 中获取直接下属 ID

  • 本文关键字:ID LDAP 获取 c# .net ldap
  • 更新时间 :
  • 英文 :


我正在使用LDAP来检索组织中的层次结构。在物业直接下属下,我得到了所有在我手下举报的员工的姓名。但我想获得他们唯一的标识(可能是一些员工 ID(。我该怎么做?

你可以

试试这个-

在项目中添加System.DirectoryServices.AccountManagement引用并导入命名空间。

var listOfDirectReportsNames = // Get the list of all the directreports user names and store in list- List<string>();
var pc = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, Environment.UserDomainName);
foreach (string name in listOfDirectReportsNames)
{
    var up = new System.DirectoryServices.AccountManagement.UserPrincipal(pc);
    up.Name = name; //to test this, pass the exact LDAP Name/DisplayName/GivenName of any user
    System.DirectoryServices.AccountManagement.PrincipalSearcher searcher = new System.DirectoryServices.AccountManagement.PrincipalSearcher(up);
    var res = searcher.FindOne();
    string empID = ((System.DirectoryServices.AccountManagement.UserPrincipal)res).EmployeeId;//here you will get employee ID
    up.Dispose();
}

最新更新