How to find the file modified after a certain date using PowerShell?


To get all the files that are modified after certain days, we need to use the LastWriteTime property.

The below command shows us the files which are modified within the last 30 days in the C:\temp folder.

Get-ChildItem C:\Temp | where{$_.LastWriteTime -ge (GetDate).AddDays(-30)}

You can also use the AddMonths() or AddYears() instead of AddDays() as per your requirement.

To get all the files that are modified before 30 days, use the below command.

Get-ChildItem C:\Temp | where{$_.LastWriteTime -le (GetDate).AddDays(-30)}

To get the file modified after a specific date, you need to compare the LastWriteTime with the Date. For example, we need all the files that are modified after 01st April 2021 then we can use the below command.

$date = "04/01/2021"
Get-ChildItem C:\Temp | where{$_.LastWriteTime -ge
[DateTime]$date}

The date format specified is MM/DD/YYYY.

To get all the files modified before the date, use the below command.

$date = "04/01/2021"
Get-ChildItem C:\Temp | where{$_.LastWriteTime -le
[DateTime]$date}

Updated on: 31-Aug-2021

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements