Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert datetime in a command

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks in advance 🙂

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading