我想从LDAP查询所有用户,并获取用户的Windows 2000初始登录名,以便与外部数据进行比较。
我的代码是:
public GroupPrincipal GetGroup(string groupName)
{
var principalContext = GetPrincipalContext();
var groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName);
return groupPrincipal;
}
public List<AdGroupMember> GetGroupMembers(string groupName)
{
return (from member in GetGroup(groupName).GetMembers()
let sad = member.GetUnderlyingObject() as DirectoryEntry
let membreUpn = member as UserPrincipal
select new AdGroupMember
{
MemberName = member.SamAccountName,
RoleName = groupName,
DomainName = member.UserPrincipalName ?? member.SamAccountName + "@" + member.Context.Name,
UserGuid = member.Guid.HasValue ? member.Guid.Value.ToString() : new Guid().ToString(),
FirstName = membreUpn.GivenName,
LastName = membreUpn.Surname,
Email = membreUpn.EmailAddress,
Tel = membreUpn.VoiceTelephoneNumber,
Title = membreUpn.GetProperty("title")
}).ToList();
}
但结果并没有以MYDOMAIN \ User格式返回给我登录名,但是User@MYDOMAIN.com
例如,我有一个用户:crmadmin1,我想获得CRM2015 \ crmadmin1,这是win2K之前的登录名,但我只能获得crmadmin1@crm2015.constoso.com。
我怎样才能做到这一点?