
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find 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}
Advertisements