Saturday, 23 July 2016

C# Active Directory Get Account Status

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;
}



No comments:

Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link