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?
Best Answer
You're missing the
$_
to indicate which object'smsDS-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"
.