Home » How to Get a List of Files Modified After Certain Date in PowerShell

How to Get a List of Files Modified After Certain Date in PowerShell

To get a list of files modified after a certain date in PowerShell, you can use the Get-ChildItem cmdlet to retrieve the list of files in the specified directory and check if the file’s LastWriteTime is greater than the date.

The following method shows how you can use it.

Method 1: Get the list of files modified after a certain date

# specify the path to the directory

$directoryPath = "C:\temp\log\"

# Retrieve the list of files and compare their lastwritetime with the date

Get-ChildItem -Path $directoryPath -Recurse | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}

This example will return a list of all file names in the specified directory modified within the last 7 days.

The following example shows how to use this method.

Get a List of Files Modified After a Certain Date

You can use the Get-ChildItem cmdlet in PowerShell to retrieve the list of files and check if the LastWriteTime property of the file is greater than the specified date to the list of files modified after it.

The following example shows how to do it.

# specify the path to the directory

$directoryPath = "C:\temp\log\"

# Retrieve the list of files and compare their lastwritetime with the date

Get-ChildItem -Path $directoryPath -Recurse | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}

Output:

PowerShell list files modified after date
PowerShell list files modified after the date

In this PowerShell script, the $directoyPath variable stores the path to the directory. The Get-ChildItem cmdlet uses the -Path parameter to specify the directory path $directoryPath to retrieve all the files and pipe them to the Where-Object cmdlet.

The Where-Object command checks the LastWriteTime of the file with the specified date (in this case 7 days) to see if the files modified in the last 7 days.

Finally, it lists files modified within the last 7 days in the specified directory and subdirectories.

Conclusion

I hope the above article on getting the list of files modified after certain date using PowerShell is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.