[英]Powershell password expiration date filtering
Im currently trying to pull a CSV that returns users whose AD password is expiring within a date range.我目前正在尝试提取一个 CSV,它返回 AD 密码在某个日期范围内到期的用户。 I currently have the code below, which pulls all users and expiration dates and emails.
我目前有下面的代码,它会提取所有用户和到期日期和电子邮件。 Was wondering how to filter this statement by date so I could know all users 5 days from expiration?
想知道如何按日期过滤此声明,以便我可以在过期 5 天后了解所有用户?
get-aduser -filter * -properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" , EmailAddress, DisplayName | Select-Object -Property "Displayname", EmailAddress,@{Name="Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} | Export-Csv -Path c:\support\PasswordExpiration.csv -Encoding ascii -NoTypeInformation
Add in a Where-Object
before the Export-Csv
.在
Export-Csv
之前添加一个Where-Object
。 This will return all the users that have an expiration date less than 5 days in the future这将返回所有到期日期少于未来 5 天的用户
Get-ADUser -Filter * -Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" , EmailAddress, DisplayName |
Select-Object -Property "Displayname", EmailAddress,@{Name="Expiration Date";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} |
Where-Object { $_.'Expiration Date' -lt (Get-Date).AddDays(5) } |
Export-Csv -Path c:\support\PasswordExpiration.csv -Encoding ascii -NoTypeInformation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.