Active Directory의 사용자 개체에 대한 다양한 속성에 액세스하고 있습니다. 나는 아래에 내가 쓴 방법을 가지고있다.UserPrincipal AccountLockoutTime always null
항상 null로 돌아 오는 AccountLockoutTime을 제외한 모든 속성에서 작동하는 It.
public IEnumerable<ActiveDirectoryAccount> GetUserAccounts(string samAccountName)
{
PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "domainname.co.za:3268");
UserPrincipal userPrincipal = new UserPrincipal(pricipalContext);
userPrincipal.SamAccountName = "*" + samAccountName + "*";
PrincipalSearcher principalSearcher = new PrincipalSearcher(userPrincipal);
ICollection<ActiveDirectoryAccount> result = new List<ActiveDirectoryAccount>();
foreach (UserPrincipal userSearchResult in principalSearcher.FindAll())
{
ActiveDirectoryAccount account = new ActiveDirectoryAccount()
{
AccountLockedOut = userSearchResult.IsAccountLockedOut(),
DistinguishedName = userSearchResult.DistinguishedName,
Description = userSearchResult.Description,
Enabled = userSearchResult.Enabled,
GUID = userSearchResult.Guid,
LastLogon = userSearchResult.LastLogon,
LastPasswordSet = userSearchResult.LastPasswordSet,
// The below line always comes back as null
LockoutTime = userSearchResult.AccountLockoutTime,
PasswordNeverExpires = userSearchResult.PasswordNeverExpires,
SAMAccountName = userSearchResult.SamAccountName,
SmartcardLogonRequired = userSearchResult.SmartcardLogonRequired,
UserCannotChangePassword = userSearchResult.UserCannotChangePassword,
UserPrincipalName = userSearchResult.UserPrincipalName
};
if (userSearchResult.GetUnderlyingObjectType() == typeof(DirectoryEntry))
{
using (DirectoryEntry entry = (DirectoryEntry)userSearchResult.GetUnderlyingObject())
{
account.WhenChanged = (DateTime)entry.Properties["whenChanged"].Value;
account.WhenCreated = (DateTime)entry.Properties["whenCreated"].Value;
// Tried the below to get the data as well but no luck.
if (userSearchResult.IsAccountLockedOut())
{
if (entry.Properties["lockoutTime"].Value != null)
{
account.Test = (string)entry.Properties["lockoutTime"].Value;
}
}
}
}
result.Add(account);
}
principalSearcher.Dispose();
return result.ToList();
}
위의 코드가 IsAccountLockedOut을 읽을 수 있는지 확인하기 위해 계정을 잠갔습니다. 그것은 사실을 반환 할 수 있습니다. userSearchResult.AccountLockoutTime 또는 (string) entry.Properties [ "lockoutTime"]에 대해 항상 null을 반환합니다. 값;
Active Directory에서 lockoutTime 속성을 확인했으며 계정을 잠그면 사용자 계정에 대한 채워집니다.
어떤 아이디어가 잘못 되었나요?
미리 감사드립니다. entry.Properties["lockoutTime"].Value
을 통해 얻은 경우 :
크리스