Muh*_*aja 7 .net c# active-directory
我有一个ADUsers列表,我想检查是否有任何用户的密码即将到期,但我找不到任何要检查的属性.
Rob*_*ine 13
这应该可以找到每个用户密码到期之前的剩余时间:
private static TimeSpan GetTimeRemainingUntilPasswordExpiration(string domain, string userName)
{
using (var userEntry = new System.DirectoryServices.DirectoryEntry(string.Format("WinNT://{0}/{1},user", domain, userName)))
{
var maxPasswordAge = (int)userEntry.Properties.Cast<System.DirectoryServices.PropertyValueCollection>().First(p => p.PropertyName == "MaxPasswordAge").Value;
var passwordAge = (int)userEntry.Properties.Cast<System.DirectoryServices.PropertyValueCollection>().First(p => p.PropertyName == "PasswordAge").Value;
return TimeSpan.FromSeconds(maxPasswordAge) - TimeSpan.FromSeconds(passwordAge);
}
}
Run Code Online (Sandbox Code Playgroud)
注意:您需要添加引用System.DirectoryServices.
| 归档时间: |
|
| 查看次数: |
6779 次 |
| 最近记录: |