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

How to output file creation time with milliseconds with PowerShell?

I am trying to output file creation time with milliseconds using PowerShell.

This works but only outputs seconds:

Get-ChildItem *_971*.* -Force | Select-Object FullName, CreationTime

If I try to format the timestamp like this:

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

Get-ChildItem *_971*.* -Force | Select-Object FullName, CreationTime.ToString('yyyyMMdd HH:mm:ss.fff')

I get an error:

Select-Object : A positional parameter cannot be found that accepts argument 'yyyyMMdd HH:mm:ss.fff'.
At line:1 char:33

>Solution :

You need to use a calculated property to evaluate the expression CreationTime.ToString('yyyyMMdd HH:mm:ss.fff') over each pipeline item:

Get-ChildItem *_971*.* -Force |
    Select-Object FullName, @{ N='CreationTime'; E= { $_.CreationTime.ToString('yyyyMMdd HH:mm:ss.fff') }}
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