Powershell get-childitem and date modified

19 April,2017 by Jack Vamvas

Question: I can list out the files of a directory using Powershell get-childitem , but how can I display the Windows sdirectory “date modified” column as part of the recordset returned by get-childitem?

The code I’m using is :

Get-ChildItem -path "Y:\myfolder"| select name


Answer: The Powershell code you’ve presented just needs to be extended by adding another select item : lastwritetime


Get-ChildItem -path "Y:\myfolder"| select name,lastwrite


To sort by lastwritetime add a sort-object filter

Get-ChildItem -path "Y:\myfolder"| select name,lastwritetime | sort-object -property lastwritetime


To export the results to a CSV you can extent the powershell code by adding the Export-CSV cmdlet

Get-ChildItem -path "Y:\myfolder"| select name,lastwritetime | sort-object -property lastwritetime| Export-CSV -notype Y:\myfile.csv



Author: Jack Vamvas (http://www.sqlserver-dba.com)


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on Powershell get-childitem and date modified

sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer