PowerShell: Get List of Files Modified After Certain Date


You can use the following syntax in PowerShell to get a list of files in the current directory that have been modified after a certain date:

Get-ChildItem -Path . -Recurse| Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-30)}

This particular example will list out all file names in the current directory that have been modified within the last 30 days.

Note: To get a list of files for a different number of recent days, simply change the number in the AddDays() method.

The following example shows how to use this syntax in practice.

Example: Get List of Files Modified After Certain Date Using PowerShell

Suppose that our current directory has the following path:

  • C:\Users\bobbi\OneDrive\Documents\test_data

We can type Dir to list out all files in this current directory:

Suppose that we we would like to list out only the files that have been modified in the past 30 days.

We can use the following syntax to do so:

Get-ChildItem -Path . -Recurse| Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-30)} 

The following screenshot shows how to use this syntax in practice:

PowerShell get list of files modified after certain date

This returns the three files that have been modified in the past 30 days:

  • cool_data.xlsx
  • new_data.txt
  • that_data.txt

We can view the LastWriteTime column in the output to see the date and time that each file was most recently modified.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Get Most Recently Modified File in Directory
PowerShell: How to List Files in Directory by Date
PowerShell: How to List All Files in Directory to Text File
PowerShell: How to Delete All Files with Specific Extension

Leave a Reply