I have the following piece of code that works fine to output the user's displayname and the accountExpires attribute from AD. I am running them on commandline because of restricted mode at work:
$objSearch.findall() | %{" " + $_.properties.displayname + "| " + $_.properties.accountexpires}
Now I need to convert this output, specifically the accountExpires attribute to a humanly readable date. After googling I figured that I can use something like the below to convert between the accountExpires and a datetime.
[datetime]::fromfiletime(129138320987173880)
But I am having issues combining the two. I tried the following:
$objSearch.findall() | %{" "+ $_.properties.displayname + " " + [datetime]::fromfiletime($_.properties.accountexpires)}
Cannot convert argument "0", with value: "System.DirectoryServices.ResultPropertyValueCollection", for "FromFileTime" to type "System.Int64": "Cannot convert the "System.DirectoryServices.ResultPropertyValueCollection" value of type "System.DirectoryServices.ResultPropertyValueCollection" to type "System.Int64"." At line:1 char:96 + $objSearch.findall() | %{" "+ $.properties.displayname + " " + [datetime]::fromfiletime <<<< ($.properties.accountexpires)} + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
$objSearch.findall() | %{" "+ $_.properties.displayname + " " + [datetime]::fromfiletime $_.properties.accountexpires}
Unexpected token '' in expression or statement. At line:1 char:99 + $objSearch.findall() | %{"This is "+ $.properties.displayname + " " + [datetime]::fromfiletime $_ <<<< .properties.accountexpires} + CategoryInfo : ParserError: (_:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
How can I convert the accountExpires to a humanly readable date?