mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-23 16:33:20 +01:00
29 lines
735 B
PowerShell
Executable File
29 lines
735 B
PowerShell
Executable File
<#
|
|
.SYNOPSIS
|
|
list-unused-files.ps1 <dir-tree> <days>
|
|
.DESCRIPTION
|
|
Lists files in the <directory tree> with last access time older than <days>
|
|
.EXAMPLE
|
|
PS> .\list-unused-files.ps1 C:\ 90
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz
|
|
License: CC0
|
|
#>
|
|
|
|
param([string]$DirTree = "", [int]$NumberOfDaysUnused = 99)
|
|
|
|
write-host "Listing files in $DirTree with last access time older than $NumberOfDaysUnused days"
|
|
|
|
try {
|
|
$cutOffDate = (Get-Date).AddDays(-$NumberOfDaysUnused)
|
|
|
|
Get-ChildItem -path $DirTree -recurse | Where-Object {$_.LastAccessTime -le $cutOffDate} | select fullname
|
|
|
|
exit 0
|
|
} catch {
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|