【问题标题】:How to find manager of department如何找到部门经理
【发布时间】:2013-05-21 01:52:25
【问题描述】:

我目前正在使用 Active Directory。我可以拉出在一个部门工作的每个人的名单,但我不知道如何判断哪个是经理。

public void MemberOf(string department)
        {
            DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");

            DirectorySearcher ds = new DirectorySearcher(de);

            ds.Filter = ("(&(objectCategory=person)(objectClass=User)(department=" + department + "))");
            ds.SearchScope = SearchScope.Subtree;

            foreach (SearchResult temp in ds.FindAll())
            {
                string test1 = temp.Path;
            }
        }

这将返回一个人员列表,其中一个是经理,其余的人是直接向经理汇报。

【问题讨论】:

  • 你怎么知道?经理的Manager 属性是否为空?或者经理是否有其他一些独特的财产价值?经理是否例如属于他的员工不属于的特定组?
  • 我不确定这是问题的一部分。 ManagerA 有自己的经理。然后员工将 ManagerA 列为他们的经理。我认为必须有一种简单的方法来查看谁管理一个部门。 @marc_s
  • 嗯,问题是:department 本身(OU 容器)没有 manager 属性。很可能会有类似“经理”组或您可以检查的东西 - 这将是可靠地找到这些经理的最简单方法。

标签: c# active-directory ldap


【解决方案1】:

这不是最好的实现,但不知道你想用它做什么......你将如何获取数据......等等,这是一个快速而肮脏的实现:

private void Test(string department)
    {
        //Create a dictionary using the manager as the key, employees for the values
        List<Employee> employees = new List<Employee>();

        DirectoryEntry de = new DirectoryEntry("LDAP://server.server.com");
        DirectorySearcher ds = new DirectorySearcher(de);

        ds.Filter = String.Format(("(&(objectCategory=person)(objectClass=User)(department={0}))"), department);
        ds.SearchScope = SearchScope.Subtree;

        foreach (SearchResult temp in ds.FindAll())
        {
            Employee e = new Employee();

            e.Manager = temp.Properties["Manager"][0].ToString();
            e.UserId = temp.Properties["sAMAccountName"][0].ToString();
            e.Name = temp.Properties["displayName"][0].ToString();

            employees.Add(e);
        }
    }

    public class Employee
    {
        public string Name { get; set; }
        public string Manager { get; set; }
        public string UserId { get; set; }
    }

【讨论】:

  • 谢谢,这实际上帮助我到达了我需要的地方。 :)
  • 仍然需要弄清楚如何分辨谁在管理一个部门,但这确实帮助我克服了其他一些我被困住的东西。
猜你喜欢
  • 2016-03-21
  • 2021-06-20
  • 1970-01-01
  • 2023-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
相关资源
最近更新 更多