When do I have to change my Password

Hello all,

I am sure I am not the only one that has been working on something only to get weird error messages about access denied, only to realize that my password had expired.

Below are a couple of code snippets you can use to have PowerShell tell you when your password will expire.

First, I am setting the variable to the user id I want to query. We will use the $user variable in the snippet.

$user = <Your User ID>

The first snippet will list two columns of data, one is user name and the other is the date of expiration.

Get-ADUser  –Identity $user –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

The second snippet does the same thing, but only outputs the number of days till expiration. I prefer this method because I usually want to know how long I have before expiration rather than the specific date. As an added benefit, we prepend the string "Days till expiration: " to the string making it more human readable.

"Days til expiration: " + (([datetime]::FromFileTime((Get-ADUser -Identity $user -Properties "msDS-Use


Hopefully you find this helpful.

Leave a Reply