Convert accountExpires (obtain from Get-ADComputer )to human readable format

Hi all,

I want to convert the result “accountExpires” returned from Get-ADComputer to human readable format
I google the answers, but none of them works for me, I tried below way, but it doesn’t work.

$mytime=(Get-ADComputer -Identity xxxxxxYYVV -Properties accountExpires).accountExpires
$myconvert=[DateTime]::FromFileTime($mytime)

it shows me below error:

Exception calling "FromFileTime" with "1" argument(s): "Not a valid Win32 FileTime.
Parameter name: fileTime"
At line:1 char:1
+ $myconvert=[DateTime]::FromFileTime($mytime)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

I also want to implement it with just one cmdlet, something like this:

Get-ADComputer -Identity xxxxxxxYYVV -Properties accountExpires FOLLOW SOME MAGIC

Any one can help ?

Hi, welcome back :wave:

What is the value of AccountExpires being returned for that computer? I suspect you’re trying to convert the value 9223372036854775807 (account never expires). That’s not a valid Win32 FileTime so you can’t convert it.

it does is 9223372036854775807

BTW , how to write my cmdlet if I want to convert the returned value (not the never expires number) to human readable with just in one line code.

This is one way, but there are several others.

(Get-ADComputer -Identity xxxxxxYYVV -Properties accountExpires).accountExpires |
    ForEach-Object { [DateTime]::FromFileTime($_) }

The linebreak after the | is just to make the post more readable.