我有一个名为Stack Over Flow IT的Active Directory组。需要找到像stackoverflowit@stackoverflow.com这样的AD组电子邮件。无需查找AD用户列表。
如何查找AD组电子邮件地址?
或者如何使用AD组电子邮件地址查找AD组名称?
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");我无法使用上面的group实例代码找到Active Directory组电子邮件地址。
发布于 2021-09-22 05:15:23
群发邮件
您可以执行以下操作:
PropertyValueCollection email = ((DirectoryEntry) group.GetUnderlyingObject()).Properties["mail"];如果您有可用的RSAT,您可以使用以下命令验证您的代码(在powershell中):
get-adgroup -Identity "Stack Over Flow IT" -properties mail | select name,mail | sort mail通过邮件查找组
下面是实现完整性的相反方法:
// replace stuff inside [] to match your environment
DirectoryEntry root = new DirectoryEntry("LDAP://dc=[YOUR DC]", [username], [password], AuthenticationTypes.Secure);
DirectorySearcher groupSearcher = new DirectorySearcher(root);
groupSearcher.Filter = "(mail=stackoverflowit@stackoverflow.com)";
groupSearcher.PropertiesToLoad.Add("name");
foreach (SearchResult groupSr in groupSearcher.FindAll())
{
ResultPropertyValueCollection groupName = groupSr.Properties["name"];
// do something with finding
}https://stackoverflow.com/questions/69278143
复制相似问题