在找到所有用户时,Active Directory不是每个人都被正确返回

时间:2014-10-25 10:20:33

标签: c# active-directory

我正在尝试从Active Directory中的组中获取所有用户。一切都很好,但从349用户到最终一些东西不起作用。它仍然正确保存“SamAccountName”,但其他属性为null(但实际上它有值)。这个问题的解决方案是什么?

PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain, daneAD.kontroler, AD.editDomena(daneAD.domena), daneAD.user, daneAD.haslo);
UserPrincipal u = new UserPrincipal(ADDomain);

GroupPrincipal group = GroupPrincipal.FindByIdentity(ADDomain, daneAD.grupa);

if (group != null)
{
    foreach (Principal p in group.GetMembers())
    {
        UserPrincipal result = p as UserPrincipal;

        if (result != null && result.DisplayName != null)
        {
            ADoutput user = new ADoutput();

            user.username = result.SamAccountName;
            user.firstname = result.GivenName;
            user.surname = result.Surname;
            user.mail = result.EmailAddress;
            user.isActive = result.Enabled;
            user.department = result.GetProperty("department");

            if (result.AccountExpirationDate.HasValue)
            {
               DateTime expiration = result.AccountExpirationDate.Value.ToLocalTime();

               user.lockdate = string.Format("TIMESTAMP '{0}-{1}-{2} {3}:{4}:{5}.{6}'", expiration.Year, expiration.Month, expiration.Day, expiration.Hour, expiration.Minute, expiration.Second, expiration.Millisecond);
            }
            else
            {
                user.lockdate = "null::timestamp";
            }

            // I save user there
        }
    }
}

0 个答案:

没有答案