1

I'm am trying to get a list of the users in my AD Domain along with their password expiration. I have this so far in PowerShell:

get-aduser -filter * -properties "msDS-UserPasswordExpiryTimeComputed" | select name,samaccountname,@{Name="Expiry";Expression="msDS-UserPasswordExpiryTimeComputed"}

Which results in something like this:

name                       samaccountname                                Expiry
----                       --------------                                ------
longneck                   longneck                          129802700808178073

How can I convert that Expiry column to a datetime? I've tried this:

get-aduser -filter * -properties "msDS-UserPasswordExpiryTimeComputed" | select name,samaccountname,@{Name="Expiry";Expression={[datetime]::FromFileTime("msDS-UserPasswordExpiryTimeComputed")}}

But that just results in a blank Expiry column.

name                       samaccountname                                Expiry
----                       --------------                                ------
longneck                   longneck                          

What am I doing wrong?

1 Answer 1

1

You're missing the $_ to indicate which object's msDS-UserPasswordExpiryTimeComputed attribute to use in your expression. The $_ variable is the default current object in the pipeline. You would find the value in $_."msDS-UserPasswordExpiryTimeComputed".

Get-ADUser -Filter * -Properties "msDS-UserPasswordExpiryTimeComputed" | 
  Select-Object name,samaccountname,@{Name="Expry";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .