M
M
Mr. Anderson2020-07-30 04:29:30
PowerShell
Mr. Anderson, 2020-07-30 04:29:30

How to display users whose password is expiring?

Good morning.

There is such a piece that displays the user's full name, when the password was last changed, and whether the password has expired and whether the checkbox says that the password never expires.

$data = Get-ADUser -Filter * -SearchBase "DC=lala,DC=local" -Properties PasswordExpired,PasswordLastSet,PasswordNeverExpires
$data | ft -Property Name,PasswordLastSet,PasswordNeverExpires,PasswordExpired


Everything works and everything is great, but how can I display only those users whose password expires in 2 days? On the Internet, I did not find a clear answer.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew AT, 2020-07-30
@roman_tonkoshkurov

Get-ADUser -Filter * -SearchBase "DC=lala,DC=local" -Properties msDS-UserPasswordExpiryTimeComputed | ?{ (Get-Date).adddays(2) -gt [datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")} | select name | sort name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question