Saturday, 26 May 2018

List files for a specific date

There often comes a time when I'd like to list (select) files for a specific date. For example, if I'm looking for log files for a particular date.

The following PowerShell code can be used for this purpose.


1:  $path = 'C:\Family\powershell';
2:  $targetDate = '2018-04-09';
3:
4:  Get-ChildItem -Path $path -File |
5:    Where-Object {$_.LastWriteTime.ToString("yyyy-MM-dd") -eq $targetDate}
6:
7:  Write-Host 'All done now';
8:


In this example, I'm looking for files with a LastWriteTime of 2018-04-09. All other files will be ignored.


Keywords: powershell files lastwritetime target date

No comments:

Post a Comment