List-UnusedFiles
List unused files in a directory tree
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 # success
} catch {
"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}Specifies the path to the directory tree (current working dir by default)
Specifies the number of days (100 by default)