Skip to content

Instantly share code, notes, and snippets.

@tevkar
Last active February 20, 2021 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tevkar/f1633e86a7aa3def560cb1446faaa17c to your computer and use it in GitHub Desktop.
Save tevkar/f1633e86a7aa3def560cb1446faaa17c to your computer and use it in GitHub Desktop.
Total size of files older than a specific number of days
# Provided by itefix.net
Param
(
[string]$path,
[int]$numberDays
)
$cutOffDate = (Get-Date).AddDays(-$numberDays)
$results =
Get-ChildItem -Path $path -recurse |
Where-Object {$_.LastAccessTime -le $cutOffDate} |
select name, fullname, length, lastaccesstime
$size = ($results | measure -sum length | % {$_.sum / 1gb}).ToString("#.##")
Write-Host "Path: $path, Age: $numberDays days, size: $size GB"
@tevkar
Copy link
Author

tevkar commented Feb 1, 2021

Usage: .\File_Size_With_Age.ps1 -path c:\temp -numberDays 90

Provided by itefix.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment