Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created April 23, 2025 01:21
Show Gist options
  • Select an option

  • Save cbaragao/75c0eb46933d36aabcff7ea37ff9a01c to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/75c0eb46933d36aabcff7ea37ff9a01c to your computer and use it in GitHub Desktop.
function Get-RecentFiles {
param (
[string]$Path = ".",
[int]$Days = 1,
[switch]$Recurse,
[string]$Extension
)
if (-Not (Test-Path $Path)) {
Write-Error "Path not found: $Path"
return
}
$cutoff = (Get-Date).AddDays(-$Days)
$files = Get-ChildItem -Path $Path -File -Recurse:$Recurse |
Where-Object { $_.LastWriteTime -gt $cutoff -and $_.Extension -eq $Extension}
return $files | Select-Object Name, LastWriteTime, Length, FullName
}
$file = Get-RecentFiles -Path "C:\Path\To\Files" -Days 100 -Recurse -Extension ".csv"
$file | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment