我需要将 Active Directory 中的 pwdLastSet 字段与当前日期进行比较,如果该日期差是可配置的数字(由客户端固定),我们需要触发密码即将过期的电子邮件。此日期比较还需要使用 Active Directory 中的 LastLoginTimeStamp 完成以发送电子邮件。比较这些字段的最佳方法是什么,因为 pwdLastSet 是一个长整数,并且无法使用 DirectorySearcher 过滤器与当前日期进行比较。
问问题
1671 次
3 回答
0
查看密码何时到期
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties “DisplayName”, “msDS-UserPasswordExpiryTimeComputed” |
Select-Object -Property “Displayname”,@{Name=“ExpiryDate”;Expression={[datetime]::FromFileTime($_.“msDS-UserPasswordExpiryTimeComputed”)}} | export-csv -path c:\paswsword-expiring.csv
查看上次设置密码的时间
Get-ADUser -filter * -properties Displayname,PasswordLastSet | select displayname,passwordlastset |Format-List
设置电子邮件警报
http://www.powershelladmin.com/wiki/Active_directory_password_expiration_notification
于 2016-07-12T17:53:14.083 回答
0
您可以通过使用命名空间中类的可为DateTime
空LastPasswordSet
属性来获取类型中目录用户的最后密码设置日期。 UserPrincipal
System.DirectoryServices.AccountManagement
如果User must change password at next logon
选中选项,则LastPasswordSet
属性返回null
值。否则,它会返回最后一次在 type 中设置密码的日期和时间DateTime
。然后,您可以将日期与DateTime.Compare
mathod 进行比较。
using(PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, Username);
//? - to mark DateTime type as nullable
DateTime? pwdLastSet = (DateTime?)user.LastPasswordSet;
int delta = 7;
if (pwdLastSet != null)
{
if (DateTime.Compare((DateTime)pwdLastSet, DateTime.Now) < delta)
{
//send email
...
}
}
}
于 2016-07-16T16:21:01.983 回答
0
从 pwdLastSet 获取日期时间:
SearchResult sr = ds.FindOne();
hacked = DateTime.FromFileTime((long)sr.Properties["pwdLastSet"][0]);
请参阅Casting ActiveDirectory pwdLastSet 属性而不使用 ActiveDs和检查时间跨度
于 2016-07-12T07:39:42.917 回答