Get Files Modified on a Specific Date in PowerShell

This sample defines a PowerShell function that lists files in a directory that were modified on a given date:

                                        
  Function Get-ModifiedFiles([string]$path,[DateTime]$date) {
    Get-ChildItem -Path $path | ?{$_.LastWriteTime.Date -eq $date.Date}
  }

                                        

The date that you pass into the function can either be a DateTime variable that you have defined or you can pass in a valid string like "5/30/2013" and PowerShell will automatically convert it into a DateTime object for you.

Examples of using this sample:

                                        
  C:\Windows\system32> Get-ModifiedFiles "C:\Files\" "9/25/2013"
  C:\Windows\system32> Get-ModifiedFiles "C:\Files\" (get-date)
  C:\Windows\system32> Get-ModifiedFiles "C:\Files\" (get-date).AddDays(-1)
  C:\Windows\system32> Get-ModifiedFiles $processDir $yesterdayDate

                                        

Tip: You could modify this function to look for a minimum file size or only include modifications made by a certain user by looking at other properties of the FileInfo object in the function.


© 2019 Embrs.net