I'm trying to get all users from group in Active Directory. Everything is fine, but from 349 user to the end something doesn't working. It still saves properly "SamAccountName", but other properties are null (but in fact it has value). What is the solution for this problem ?
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
}
}
}