从活动目录结果中获取电子邮件
本文关键字:获取 电子邮件 结果 活动 | 更新日期: 2023-09-27 18:18:26
我有以下功能,但我无法获得电子邮件和其他东西,如电话号码。我要怎么做才能得到?
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;
}
string department是AD中给定的组(可以是"guest"或"admin"或其他)
try this:
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()