Reputation: 455
I wonder, whether it is possible to grammatically get the AD Group (name) from the e-mail address of the group (the left part of the e-mail does not match to the group name)?
I need in my code the GroupPrincipal.FindByIdentity(ctx, groupName); but it seems does not work with the e-mail as the input. It worked only with the group name on the input. There is also 3rd param - Identity type enum, but none of value seem to work with the e-mail address.
Exist there any solution how to get the group name (A way Like Outlook does (entering email and then pressing Ctrl+K) the group name is shown :) ?)
Upvotes: 0
Views: 535
Reputation: 4261
Generally speaking an Active Directory mail-enabled account should have a proxyAdresses LDAP attribute, so a simple query should work, i.e.:
var searchedEmail = "[email protected]";
var ds = new DirectorySearcher($"proxyAddresses=smtp:{searchedEmail}", new string[] { "cn" });
Console.WriteLine(ds.FindOne().Properties["cn"][0]);
Upvotes: 2