从Active Directory结果中获取电子邮件

时间:2016-11-17 09:33:38

标签: c# active-directory

我有以下功能,但我无法收到电子邮件和其他类似电话号码的内容。我能做些什么来做到这一点?

public static List<AdEmployees> CreateEmployeeList(string department)
    {
        List<AdEmployees> employees = new List<AdEmployees>();

        PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain);
        GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, department);

        if (group != null)
        {
            foreach (Principal principal in group.Members)
            {
                employees.Add(new AdEmployees() { name = principal.Name });
            }
        }
        return employees;
    }

字符串部门是广告中的特定组(可以是“访客”或“管理员”或其他内容)

1 个答案:

答案 0 :(得分:0)

试试这个:

PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain);
        GroupPrincipal group = GroupPrincipal.FindByIdentity(pricipalContext, department);

        if (group != null)
        {
            foreach (Principal principal in group.Members)
            {
                UserPrincipal user = UserPrincipal.FindByIdentity(pricipalContext, principal.Name);
                employees.Add(new AdEmployees() { name = user.Name });
            }
        }

这种方式找不到像“Office”这样的广告对象。然后你可以尝试

UserPrincipal tu = principal as UserPrincipal;
DirectoryEntry de = tu.GetUnderlyingObject() as DirectoryEntry;
var store = de.InvokeGet("physicalDeliveryOfficeName").ToString()