Created
June 9, 2014 03:14
-
-
Save withinboredom/0806d77dd317d657959d to your computer and use it in GitHub Desktop.
Deletes a file if over a certain size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pick your file | |
$Dir = "F:\MyDir\stuff.cache" | |
#Max size in megs (gig = 1024 megs | |
$SizeMax = 1024 | |
#get's the size in mb of the file(s) | |
$Size = (Get-ChildItem $Dir| Measure-Object -property length -sum) | |
# convert it to megs | |
$SizeMb="{0:N2}" -f ($size.sum / 1MB) + "MB" | |
# delete if calulated size is greater than set size above | |
if ($sizeMb -ge $sizeMax) { | |
# and delete them | |
Get-ChildItem $dir -Recurse | Remove-Item –Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment