如果我有 Active Directory 组的名称,如何获取成员列表或其电子邮件地址?
问问题
3025 次
2 回答
8
void Main()
{
string groupName = "somegroup";
string domainName = "somedomain";
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName))
{
using(GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName))
{
var sams = from x in grp.GetMembers(true) select new {x.SamAccountName, };
var users = from sam in sams.Distinct()
let usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, sam.SamAccountName)
select new { usr.SamAccountName, usr.DisplayName, usr.EmailAddress};
//do something with users...
}
}
}
于 2013-03-11T20:51:40.797 回答
1
在这个 url 中有一篇关于 C# 的完整的 AD 文章http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#42,用户存储为 DiretoryEntry查看属性属性 http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.properties(v=vs.100).aspx
于 2013-03-11T20:48:12.080 回答