Monday, July 27, 2015

PowerShell - Find All Files of Type by Date

$limit = (Get-Date).AddDays(-15)
#$path = "C:\Some\Path"
$path = "C:\Temp"

# Delete files older than the $limit.
# Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit -and $_.Extension -eq ".txt" }


$limit = (Get-Date).AddDays(-1)
$path = "C:\Temp"
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit -and $_.Extension -eq ".BAK" }

No comments: