Skip to content

Instantly share code, notes, and snippets.

@jamesmstone
Last active November 24, 2022 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmstone/a7f4b74dd701407b1f4ce5a6928a4a25 to your computer and use it in GitHub Desktop.
Save jamesmstone/a7f4b74dd701407b1f4ce5a6928a4a25 to your computer and use it in GitHub Desktop.
A collection of PowerShell scripts for finding unused files
function directory-summary($dir=".") {
get-childitem $dir |
% { $f = $_ ;
get-childitem -r $_.FullName |
measure-object -property length -sum |
select @{Name="Name";Expression={$f}},Sum}
}
Function Get-NeglectedFiles
{
Param([string[]]$path,
[int]$numberDays)
$cutOffDate = (Get-Date).AddDays(-$numberDays)
Get-ChildItem -Path $path -r |
Where-Object {$_.LastAccessTime -le $cutOffDate}
}

in powershell load the scripts:

  • directory-summary {path} where {path} is the path to get folder size of
  • Get-NeglectedFiles -path c:\fso -numberDays 60 | select name, lastaccesstime
  • delete files older than 60 days: dir |? {$_.CreationTime -lt (get-date).AddDays(-60)} | del

Note these scripts were taken from :

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