Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save oscarandreu/79d50645e9da35c7f72f to your computer and use it in GitHub Desktop.

Select an option

Save oscarandreu/79d50645e9da35c7f72f to your computer and use it in GitHub Desktop.
PowerShell clean directory when exceeds a given size
$folder = (dir 'C:\Resources\Directory' | ? {$_.PSIsContainer -eq $True})
$objFSO = New-Object -com Scripting.FileSystemObject
foreach ($folder in $folders){
if($folder.Name -match 'ImageResizerOutputCache'){
$dir = 'C:\Resources\Directory\'+ $folder.Name + '\*'
$size = $objFSO.GetFolder($folder.FullName).Size
$size /= 1024#1073741824#1048576#1024
if($size -gt 6000){
Remove-Item $dir -recurse
}
Write-Host $dir
Write-Host $size
}
}
Write-Host 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment