How to Find Files Older Than a Specific Date using PowerShell?

Recently, one of my clients wanted to list down old files from a shared drive in their New York office. By using PowerShell, you can identify files older than any date you choose. In this tutorial, I will show you how to find files older than a specific date using PowerShell, along with some examples, such as finding files older than 5 years or 30 days.

Find Files Older Than a Specific Date using PowerShell

There are various methods to list files older than a specific date using PowerShell. Here are those.

Method 1: Find Files Older Than a Specific Date Using Get-ChildItem and Where-Object

The best way to find old files in PowerShell is by combining Get-ChildItem (to list files) with Where-Object (to filter based on the LastWriteTime property).

We use Get-ChildItem to scan the target directory, then filter the results to show only files whose last modification date is earlier than your chosen date.

# Example: Find files older than January 1, 2025 in C:\Bijay\TSinfo Documents
$targetDate = Get-Date "2025-01-01"
Get-ChildItem -Path "C:\Bijay\TSinfo Documents" -File -Recurse | 
    Where-Object { $_.LastWriteTime -lt $targetDate }

This command will list all files in the D:\Finance\Reports folder (including subfolders) that were last modified before January 1, 2025. This is perfect for compliance checks or data cleanups in US-based organizations.

Get-ChildItem pulls all files, while Where-Object applies the filter. Using -lt (less than) ensures only files older than your target date are returned. This method is flexible and can be adapted for any date or directory.

I ran the above PowerShell script in a folder, and you can see the exact output in the screenshot below:

Find Files Older Than a Specific Date using PowerShell

Check out How to Count Files in a Folder Using PowerShell

Method 2: Find Files Older Than X Days (e.g., 30 Days, 5 Years)

If you need to find files older than a certain number of days or years—such as for quarterly cleanups or long-term retention policies—PowerShell can calculate the date dynamically.

We subtract the desired number of days or years from today’s date and use that as the cutoff.

Example 1: Files Older Than 30 Days

Here is the PowerShell script to find files older than 30 days.

# Example: List files older than 30 days in C:\Users\fewli\Downloads
$cutoffDate = (Get-Date).AddDays(-30)
Get-ChildItem -Path "C:\Users\fewli\Downloads" -File -Recurse |
    Where-Object { $_.LastWriteTime -lt $cutoffDate }

This is ideal for monthly maintenance scripts or routine file management.

Here is the exact output in the screenshot below:

PowerShell Find Files Older Than Specific Date

Example 2: Files Older Than 5 Years

Here is an example of a PowerShell script to find files older than 5 years.

# Example: Find files older than 5 years in E:\HR\Records
$cutoffDate = (Get-Date).AddYears(-5)
Get-ChildItem -Path "E:\HR\Records" -File -Recurse |
    Where-Object { $_.LastWriteTime -lt $cutoffDate }

For organizations with strict retention policies, this helps you locate files for archiving or secure deletion.

By dynamically calculating the cutoff date, you can automate these checks without manually updating the script each time.

Check out PowerShell Test-Path

Export Results to CSV for Reporting

Sometimes you may need to export results to CSV for reporting using PowerShell. PowerShell makes it easy to export the results to a CSV file.

After filtering your files, pipe the results to Export-Csv to create a spreadsheet. Here is the complete script:

# Export list of old files to CSV
$cutoffDate = (Get-Date).AddDays(-365)
Get-ChildItem -Path "F:\Legal\Cases" -File -Recurse |
    Where-Object { $_.LastWriteTime -lt $cutoffDate } |
    Select-Object FullName, LastWriteTime, Length |
    Export-Csv -Path "C:\Reports\OldFilesReport.csv" -NoTypeInformation

This approach creates a portable, easy-to-read file that can be opened in Excel or shared with auditors. You can customize the columns as needed.

Check out How to Write to a File in a PowerShell Loop

Using Creation Date Instead of Last Modified Date

Sometimes, you may need to filter by when a file was created, not just when it was last modified.

Replace LastWriteTime with CreationTime in your filter.

# Find files created before July 1, 2018 in G:\Projects\USA
$targetDate = Get-Date "2018-07-01"
Get-ChildItem -Path "G:\Projects\USA" -File -Recurse |
    Where-Object { $_.CreationTime -lt $targetDate }

This is useful for scenarios where file creation date is the primary retention metric, such as initial project documentation.

Read PowerShell Write to File UTF-8

Delete Files Older Than a Specific Date

For automated cleanup, you can delete files directly after identifying them. Always test your script first to avoid accidental data loss!

Add the Remove-Item cmdlet to delete the filtered files.

# Delete files older than 90 days in D:\Temp
$cutoffDate = (Get-Date).AddDays(-90)
Get-ChildItem -Path "D:\Temp" -File -Recurse |
    Where-Object { $_.LastWriteTime -lt $cutoffDate } |
    Remove-Item -Force

This method is ideal for managing temp folders or ensuring compliance with data retention policies. Always review the files before deletion.

Check out Delete Files Older Than X Days With Specific Extensions Using PowerShell

Conclusion

In this tutorial, I explained how to find files older than a specific date using PowerShell. By using PowerShell cmdlets like Get-ChildItem and Where-Object, you can quickly identify files older than a specific date—whether that means 30 days, 5 years, or any custom range.

Try out these examples today and let me know in the comments if they help.

You may also like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App