Recently, I was working on a project where I needed to identify all files that had been modified within the last 24 hours in a specific directory. This can be easily achieved using PowerShell.
In this tutorial, I’ll show you four different methods to find files modified in the last 24 hours using PowerShell.
Method 1: Using Get-ChildItem with Where-Object
The best way to find files modified in the last 24 hours in PowerShell is by using the Get-ChildItem cmdlet combined with Where-Object.
Here’s how you can do it:
Get-ChildItem -Path "C:\Reports" -Recurse -File |
Where-Object {$_.LastWriteTime -gt (Get-Date).AddHours(-24)} |
Select-Object FullName, LastWriteTimeIn this example, I’m checking all files in the “C:\Reports” directory and any subdirectories. The -Recurse parameter tells PowerShell to look through all subfolders, and the -File parameter ensures we’re only looking at files, not folders.
The Where-Object cmdlet filters the results to only include files whose LastWriteTime is greater than the current date minus 24 hours. Finally, I’m selecting the full path and the last modified time for easy reading.
I executed the above PowerShell script using VS Code, and you can see the exact output in the screenshot below:

This method is particularly useful when you need to search through a deep folder structure.
Check out Find Files Modified Between Dates Using PowerShell
Method 2: Using a Single-Line Command with Get-Item
If you already know the specific file you want to check, you can use the Get-Item cmdlet for a simpler approach:
$file = "C:\Reports\quarterly_sales.xlsx"
if ((Get-Item $file).LastWriteTime -gt (Get-Date).AddHours(-24)) {
Write-Host "File modified in last 24 hours" -ForegroundColor Green
} else {
Write-Host "File not modified in last 24 hours" -ForegroundColor Red
}This method is perfect when you need to check a single file and take different actions based on whether it has been modified recently or not.
Check out Show Progress When Copying Files with PowerShell Copy-Item
Method 3: Using a Custom Date Range
Sometimes you might need more flexibility than just the last 24 hours. This method allows you to specify a custom date range:
$startDate = (Get-Date).Date.AddDays(-1) # Yesterday at midnight
$endDate = (Get-Date) # Current time
Get-ChildItem -Path "D:\Documents" -Recurse -File |
Where-Object {$_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate} |
Sort-Object LastWriteTime -Descending |
Format-Table Name, LastWriteTime, Length -AutoSizeThis approach gives you precise control over the time window you’re interested in. I’ve also added sorting by modification time (newest first) and formatted the output as a table showing the file name, modification time, and file size.
This method is particularly useful for generating reports or when you need to look at files modified during a specific timeframe, such as business hours.
Check out Create a Folder with Today’s Date and Copy Files to it using PowerShell
Method 4: Using the -Filter Parameter with Get-ChildItem
For large directory structures where performance matters, using the -Filter parameter can significantly speed up the process:
$yesterday = (Get-Date).AddHours(-24)
Get-ChildItem -Path "E:\Backups" -Recurse -File |
Where-Object {$_.LastWriteTime -gt $yesterday} |
Group-Object DirectoryName |
Select-Object Name, Count, @{Name="Files"; Expression={$_.Group.Name -join ", "}}This script groups the results by directory, showing how many modified files are in each folder and listing their names. This organization is extremely helpful when dealing with large numbers of files spread across multiple directories.
Find the Most Recently Modified File
If you’re only interested in the single most recently modified file, you can use this approach:
Get-ChildItem -Path "C:\Users\Bijay\Documents" -Recurse -File |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 |
Format-List FullName, LastWriteTime, LengthThis script will return detailed information about only the most recently modified file in the specified directory structure.
Check out PowerShell Filter Operators
Additional Filter Options
You can combine the time-based filtering with other criteria:
# Find Excel files modified in the last 24 hours
Get-ChildItem -Path "C:\Reports" -Recurse -File -Include "*.xlsx", "*.xls" |
Where-Object {$_.LastWriteTime -gt (Get-Date).AddHours(-24)} |
Select-Object FullName, LastWriteTimeThis example finds only Excel files that have been modified in the last 24 hours. You can adjust the -Include parameter to match any file types you’re interested in.
Save the Results to a CSV File
If you need to analyze the results later or share them with others, you can export them to a CSV file:
Get-ChildItem -Path "C:\ImportantFiles" -Recurse -File |
Where-Object {$_.LastWriteTime -gt (Get-Date).AddHours(-24)} |
Select-Object FullName, LastWriteTime, Length |
Export-Csv -Path "C:\Reports\ModifiedFiles.csv" -NoTypeInformationThis approach creates a neat CSV file with the full path, modification time, and size of each file, which can be opened in Excel or other data analysis tools.
Check out Filter Unique Objects in PowerShell with Where-Object
Schedule the PowerShell Script for Regular Checks
Sometimes, you want to automate this process or run it as part of a scheduled task. Here’s how I usually set this up for daily reports.
Example Script
$folderPath = "C:\Data\Shared"
$timeFrame = (Get-Date).AddDays(-1)
$recentFiles = Get-ChildItem -Path $folderPath -Recurse -File | Where-Object {
$_.LastWriteTime -ge $timeFrame
}
# Export results to CSV
$recentFiles | Select-Object FullName, LastWriteTime | Export-Csv -Path "C:\Reports\ModifiedFiles_Last24Hours.csv" -NoTypeInformationHow it works:
- Set the folder path and timeframe.
- Find all files modified in the last 24 hours.
- Export the results to a CSV file for easy sharing or review.
Scheduling the Script
To automate this:
- Open Task Scheduler.
- Create a new task.
- Set it to run PowerShell with your script file as an argument.
In this tutorial, I explained how to find files modified in the last 24 hours using PowerShell.
I hope you found this article helpful. If you have any questions or suggestions, kindly leave them in the comments below.
You may also like the following tutorials:
- Find Files Modified Between Dates Using PowerShell
- List Directories and Files in PowerShell
- Create a Folder with the Current Date using PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.