Jamie McNamara Jamie McNamara - 1 year ago 227
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)}}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download