Jamie McNamara Jamie McNamara - 2 months ago 21x
PowerShell Question

accountExpires properties not changing format

so i have this one liner that returns specific properties about all users in AD.

My issue is that it keeps returning the "accountExpires" field blank and i don't know why.

If i change the script to just return the property un-formatted it work, but it's not exactly readable.

Any help would be appreciated.

Get-ADUser -Filter * -Properties * | Select Name,Enabled,whenCreated,whenChanged,@{N='accountExpires';E={[DateTime]::FromFileTime($_.accountExpires)}},@{N='LastLogon'; E={[DateTime]::FromFileTime($_.LastLogon)}}


The ActiveDirectory module has what is, to me, an annoying feature. Rather than convert dates in fields that contain dates (such as accountExpires) they have presented a second property with a similar-ish name which contains the converted value.

Get-ADUser -Filter * -Properties * | Select-Object AccountExpirationDate

This should, hopefully, get you away from the need to spin your own conversion.