在工作中的 AD 中,我们有一些启用邮件的安全组。我正在使用 System.DirectoryServices.AccountManagement 命名空间,如下所示:
List<GroupPrincipal> result = new List<GroupPrincipal>();
using (PrincipalContext domain = new PrincipalContext(ContextType.Domain, userinfo[0]))
using (UserPrincipal user = UserPrincipal.FindByIdentity(domain, username))
{
if (user != null)
{
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
int totalGroupCounter = 0;
StringBuilder output = new StringBuilder();
List<GroupPrincipal> securityGroups = new List<GroupPrincipal>();
List<GroupPrincipal> distributionGroups = new List<GroupPrincipal>();
foreach (Principal group in groups)
{
totalGroupCounter++;
if (((GroupPrincipal)group).IsSecurityGroup.Value)
securityGroups.Add((GroupPrincipal)group);
else
distributionGroups.Add((GroupPrincipal)group);
}
}
}
有了这些信息,找到群组电子邮件地址的正确方法是什么?
最佳答案
AccountManagement 库限制了您可以访问的属性。如果您想获取组的电子邮件属性,您需要将其转换回 DirectoryEntry
。对象。
PropertyValueCollection email = ((DirectoryEntry)group.GetUnderlyingObject()).Properties["mail"];
if (email.Value != null)
{
// Do something with email property
}
关于c# - 确定 AD 安全组的电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13055696/