mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 08:09:17 +01:00
23 lines
701 B
PowerShell
Executable File
23 lines
701 B
PowerShell
Executable File
#!/snap/bin/powershell
|
|
<#
|
|
.SYNTAX ./list-unused-files.ps1 <dirtree> <days>
|
|
.DESCRIPTION lists files in the <directory tree> with last access time older than <days>
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
#>
|
|
|
|
param([string]$DirTree, [int]$NumberOfDaysUnused)
|
|
|
|
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
|
|
}
|