list-unused-files
List unused files in a directory tree
#Requires -Version 5.1
param([string]$path = "$PWD", [int]$days = 100)
try {
$stopWatch = [system.diagnostics.stopwatch]::startNew()
$path = Resolve-Path "$path"
Write-Progress "Scanning $path for unused files..."
$cutOffDate = (Get-Date).AddDays(-$Days)
[int]$count = 0
Get-ChildItem -path $path -recurse | Where-Object {$_.LastAccessTime -le $cutOffDate} | Foreach-Object {
"$($_.FullName)"
$count++
}
Write-Progress -completed " "
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✅ $count unused files at 📂$path (no access for $days days, took $($elapsed)s)."
exit 0
} catch {
throw
}Specifies the path to the directory tree (current working dir by default)
Specifies the number of days (100 by default)