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

前端 未结 4 1614
天涯浪人
天涯浪人 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:45

    Use following method to get expiration date of the account-

    public static DateTime GetPasswordExpirationDate(string userId)
        {
            string forestGc = String.Format("GC://{0}", Forest.GetCurrentForest().Name);
            var searcher = new DirectorySearcher();
            searcher = new DirectorySearcher(new DirectoryEntry(forestGc));
            searcher.Filter = "(sAMAccountName=" + userId + ")";
            var results = searcher.FindOne().GetDirectoryEntry();
            return (DateTime)results.InvokeGet("PasswordExpirationDate");
        }
    

提交回复
热议问题