Home > database >  Convert datetime in a command
Convert datetime in a command

Time:07-25

Im trying to list all of the LAPS administrated computers in my network with this command:

Get-ADComputer -Filter 'ms-Mcs-AdmPwd -ne "$null"' -Properties * | fl SamAccountName,ms-Mcs-AdmPwd,ms-Mcs-AdmPwdExpirationTime

The thing is that the 'ms-Mcs-AdmPwdExpirationTime' atribute is in Epoch (i think) and i can't convert it to human readable format.

I know that i can convert this date format with [datetime]::FromFileTimeUTC(133052980152939837) and that's great, but how can I implement it in the format list canalization.

Thanks in advance :)

CodePudding user response:

You can use a calculated property to calculate the property as you need it ;-)

Get-ADComputer -Filter 'ms-Mcs-AdmPwd -ne "$null"' -Properties ms-Mcs-AdmPwd,ms-Mcs-AdmPwdExpirationTime | 
    Select-Object -Property sAMAccountName,ms-Mcs-AdmPwd,
        @{Name = 'PasswordExirationTime';Expression = {[datetime]::FromFileTimeUTC($_.'ms-Mcs-AdmPwdExpirationTime')}}

If you want to have this in a list format of course you can pipe it to a Format-List ... but please have in mind that's only for display purposes.

  • Related