public static bool GetAccountStatus(string alias, string property)
{
UserPrincipal user = UserPrincipal.FindByIdentity(GetPrincipalContext(), IdentityType.SamAccountName, alias);
DirectoryEntry directoryEntry = user.GetUnderlyingObject() as DirectoryEntry;
bool value = null;
switch (property.ToLower())
{
case "enabled":
value = (user.Enabled == true);
break;
case "accountexpire":
value = user.AccountExpirationDate() < DateTime.Now;
break;
case "passwordneverexpires":
value = (user.PasswordNeverExpires == true);
break;
}
return value;
}
{
UserPrincipal user = UserPrincipal.FindByIdentity(GetPrincipalContext(), IdentityType.SamAccountName, alias);
DirectoryEntry directoryEntry = user.GetUnderlyingObject() as DirectoryEntry;
bool value = null;
switch (property.ToLower())
{
case "enabled":
value = (user.Enabled == true);
break;
case "accountexpire":
value = user.AccountExpirationDate() < DateTime.Now;
break;
case "passwordneverexpires":
value = (user.PasswordNeverExpires == true);
break;
}
return value;
}
No comments:
Post a Comment