mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-14 12:03:59 +01:00
32 lines
828 B
PowerShell
Executable File
32 lines
828 B
PowerShell
Executable File
<#
|
|
.SYNOPSIS
|
|
Lists unused files in a directory tree
|
|
.DESCRIPTION
|
|
This PowerShell script scans and lists files in a folder with last access time older than number of days.
|
|
.PARAMETER DirTree
|
|
Specifies the path to the directory tree
|
|
.PARAMETER Days
|
|
Specifies the number of days
|
|
.EXAMPLE
|
|
PS> ./list-unused-files C:\ 100
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz / License: CC0
|
|
#>
|
|
|
|
param([string]$DirTree = "", [int]$Days = 100)
|
|
|
|
write-host "Listing files in $DirTree with last access time older than $Days days"
|
|
|
|
try {
|
|
$cutOffDate = (Get-Date).AddDays(-$Days)
|
|
|
|
Get-ChildItem -path $DirTree -recurse | Where-Object {$_.LastAccessTime -le $cutOffDate} | select fullname
|
|
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|