PowerShell: List Files by Date/Time

By Xah Lee. Date: . Last updated: .

List File Creation Time

# list file with creation time
dir -file | sort CreationTime | Format-Table Name, CreationTime

List files whose creation date is greater than a given date

# list files whose creation date is greater than a given date
dir -file -recurse | where { $_.CreationTime -gt [datetime]"2014/05/28" } | sort CreationTime | Format-Table Name, CreationTime

List File by Date Range

# list file with last write time greater than 24 hours ago
dir -file -recurse | where {$_.LastWriteTime -gt (Get-Date).AddDays(-1)}
# list file within a date range

$datemin = [datetime]::ParseExact("2021-12-11 01:00:00", "yyyy-MM-dd hh:mm:ss", [Cultureinfo]::InvariantCulture)
$datemax = [datetime]::ParseExact("2021-12-13 00:00:00", "yyyy-MM-dd hh:mm:ss", [Cultureinfo]::InvariantCulture)

dir -file -recurse -filter *.png  | where { $_.LastWriteTime -ge $datemin -and $_.LastWriteTime -le $datemax }

PowerShell: Date/Time

PowerShell

Practical How-To

list files

list dirs

on dir

on file

Windows config

misc


PowerShell in Depth

Programing PowerShell

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples