Active Directory user password expiration date .NET/OU Group Policy

前端 未结 4 1644
天涯浪人
天涯浪人 2020-11-30 10:14

I have searched the site for information and found this: ASP.NET C# Active Directory - See how long before a user's password expires

which explains how to get th

4条回答
  •  情话喂你
    2020-11-30 10:56

    The following code worked for me to get the password expiration date on both domain and local user accounts:

    public static DateTime GetPasswordExpirationDate(string userId, string domainOrMachineName)
    {
        using (var userEntry = new DirectoryEntry("WinNT://" + domainOrMachineName + '/' + userId + ",user"))
        {
            return (DateTime)userEntry.InvokeGet("PasswordExpirationDate");
        }
    }
    

提交回复
热议问题