Yourdaman
Yourdaman

Reputation: 13

Get Password expiry date for one single user in AD

I have found this script that filters me the passwprdexpirydate of enabled accounts on AD.

 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”)}}

It works fine but I would like to have it search just one specific AD account that I will type in. How do I accomplish that?

I would

Upvotes: 0

Views: 2963

Answers (2)

Cedric
Cedric

Reputation: 19

Try something like this:

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")}} |
        Where-Object {$_.DisplayName -like "Username"}

Upvotes: 0

henrycarteruk
henrycarteruk

Reputation: 13217

This is one of those times where reading the documentation would answer your question, as the examples cover this question...

You can either replace the Filter for the Identity param:

Get-ADUser -Identity USERNAME

Or, update the filter:

Get-ADUser -Filter {Name -eq "USERNAME"}

Upvotes: 2

Related Questions