

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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}
- Related Questions & Answers
- How to check the Date and time of Access (last modified) of a File using Java?
- How to find and replace the word in a text file using PowerShell?
- How to search in the file using PowerShell?
- How to edit the CSV file using PowerShell?
- How to mount the ISO file using PowerShell?
- How to dismount the ISO file using PowerShell?
- How to install the MSI file using PowerShell?
- How to get the file extension using PowerShell?
- How to create a temporary file using PowerShell?
- How to delete all the file contents using PowerShell?
- How to read the windows host file using PowerShell?
- How to convert JSON file to CSV file using PowerShell?
- How to find the date after a number of days in R?
- How to install MSI file using batch file in PowerShell?
- How to call a jQuery function after a certain delay?
Advertisements