How to Find Files Modified Between Dates Using PowerShell?

Recently, I was working on a project where I needed to identify all files that had been modified within a specific date range. As a PowerShell administrator, you may need to locate files within a specific date range. There are various methods to do so.

In this tutorial, I will show you multiple reliable methods to find files modified between dates using PowerShell.

Method 1: Using Get-ChildItem with Where-Object

The most straightforward approach is to use the Get-ChildItem cmdlet (which many PowerShell users know by its aliases dir or ls) combined with the Where-Object cmdlet to filter results.

Here’s a simple example to find files modified between January 1, 2025, and June 10, 2025:

$startDate = Get-Date "2025-01-01"
$endDate = Get-Date "2025-06-10"

Get-ChildItem -Path "C:\Reports" -Recurse -File | 
    Where-Object { $_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate }

This command will search recursively through the “C:\Reports” directory and return only files (not folders) modified within our specified date range.

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

powershell find files modified between dates

What I love about this method is its flexibility. You can easily adjust the parameters to suit your needs:

  • Change -Path to search a different location
  • Remove -Recurse if you only want to search the current directory
  • Add -Include "*.xlsx" to filter by file type (e.g., Excel files only)

The results will include the file name, size, last write time, and other properties.

Check out Show Progress When Copying Files with PowerShell Copy-Item

Method 2: Filter by Date Directly in Get-ChildItem (for Simpler Cases)

If you only care about files modified after a certain date (or before), you can filter right inside Where-Object without specifying both dates.

For example, to find all files modified after Jan 01, 2025, in a folder:

$folder = "C:\Reports"
$afterDate = Get-Date "2025-01-01"

Get-ChildItem -Path $folder -File -Recurse |
    Where-Object { $_.LastWriteTime -ge $afterDate }

You can see the exact output in the screenshot below:

find files modified between dates in powershell

Or, for files modified before a certain date:

$beforeDate = Get-Date "2025-06-10"

Get-ChildItem -Path $folder -File -Recurse |
    Where-Object { $_.LastWriteTime -lt $beforeDate }

This approach is perfect for quick checks, such as cleaning up files older than a year.

Read List Directories and Files in PowerShell

Method 3: Using the Get-ItemsBetweenDates Custom Function

In PowerShell, you can also create a reusable function to get files between dates. Then you can reuse the function.

Here is an example.

function Get-FilesBetweenDates {
    param (
        [Parameter(Mandatory=$true)]
        [string]$FolderPath,
        
        [Parameter(Mandatory=$true)]
        [DateTime]$StartDate,
        
        [Parameter(Mandatory=$true)]
        [DateTime]$EndDate,
        
        [string]$FileType = "*"
    )
    
    Get-ChildItem -Path $FolderPath -Include $FileType -Recurse -File | 
        Where-Object { $_.LastWriteTime -ge $StartDate -and $_.LastWriteTime -le $EndDate }
}

# Example usage
$start = Get-Date "2025-05-10"
$end = Get-Date "2025-06-10"
Get-FilesBetweenDates -FolderPath "C:\Projects\TaxReturns" -StartDate $start -EndDate $end -FileType "*.pdf"

This function accepts parameters for the folder path, start date, end date, and an optional file type filter. I use this approach in my automation scripts where I need to check for modified files regularly.

Check out Create a Folder with Today’s Date and Copy Files to it using PowerShell

Method 4: Using ForFiles Command for Compatibility

Sometimes you might need a solution that works in older environments or that can be easily incorporated into batch scripts. The ForFiles command can help:

# Using ForFiles through PowerShell
$startDate = (Get-Date "2023-01-01").ToString("MM/dd/yyyy")
$endDate = (Get-Date "2023-01-31").ToString("MM/dd/yyyy")

cmd /c "forfiles /P C:\Data\ClientReports /S /D +$startDate /C `"cmd /c if @fdate GEQ $startDate if @fdate LEQ $endDate echo @path @fdate`""

This approach uses the Windows forfiles command through PowerShell. While not as elegant as native PowerShell methods, it can be useful in certain scenarios where you need command prompt compatibility.

Method 5: Find Files Modified Between Dates with Formatted Output

When presenting results to others, you might want a cleaner output format:

$startDate = Get-Date "2025-05-01"
$endDate = Get-Date "2025-05-30"

Get-ChildItem -Path "C:\Invoices" -Recurse -File | 
    Where-Object { $_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate } |
    Select-Object Name, @{Name="Size (KB)"; Expression={[math]::Round($_.Length/1KB, 2)}}, LastWriteTime, FullName |
    Sort-Object LastWriteTime -Descending |
    Format-Table -AutoSize

This command searches for files modified in May 2025, then formats the output to show the file name, size in KB (rounded to 2 decimal places), last modified date, and full path, sorted with the most recently modified files first.

Read Create Files with Content Using PowerShell

Method 5: Find Files Modified Between Dates Across an Entire Drive

If you need to search an entire drive (for example, D:\), just set the path to the root of the drive. Be aware that this can take longer, especially on drives with many files.

$startDate = Get-Date "2025-05-01"
$endDate = Get-Date "2025-05-31"

Get-ChildItem -Path "D:\" -File -Recurse -ErrorAction SilentlyContinue |
    Where-Object {
        $_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate
    }

I recommend using -ErrorAction SilentlyContinue to skip over folders you don’t have access to.

Table: Quick Reference for PowerShell Date Filters

Use CaseExample Script Snippet
Files modified after a date$_ .LastWriteTime -gt $afterDate
Files modified before a date$_ .LastWriteTime -lt $beforeDate
Files modified between two dates$_ .LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate
Search subfolders (recursive)Add -Recurse to Get-ChildItem
Export results to CSVPipe to Export-Csv

Export Results to CSV or Text File

Sometimes, you might need to export results to CSV or Text files in PowerShell.

When working with large sets of files, It’s often helpful to export the results for further analysis:

$startDate = Get-Date "2025-01-01"
$endDate = Get-Date "2025-06-10"

Get-ChildItem -Path "C:\FinancialRecords" -Recurse -File | 
    Where-Object { $_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate } |
    Select-Object Name, Length, LastWriteTime, FullName |
    Export-Csv -Path "C:\Reports\ModifiedFiles2025.csv" -NoTypeInformation

This command will create a CSV file with details of all files modified during the mentioned date range, which you can then open in Excel for further analysis or sharing with team members.

PowerShell provides multiple ways to find files modified between specific dates. The method you choose depends on your specific requirements, the complexity of your search criteria, and whether you need to reuse the command.

In most cases, the simple Get-ChildItem with Where-Object approach works perfectly, but don’t hesitate to use the more advanced techniques when needed.

I hope you found this article helpful. If you have any questions or want to share your own approaches, please leave them in the comments below.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.