Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this is mostly stolen from http://stackoverflow.com/a/19326146/18524
- function Cleanup-Dir
- {
- param([string]$path, [int]$limit)
- $minDay = (Get-Date).AddDays(-1 * $limit)
- # delete files older than $limit
- Get-ChildItem -Path $path -Recurse -Force `
- | Where-Object { !$_.PSIsContainer -and $_.LastWriteTime -lt $minDay } `
- | Remove-Item -Force -ErrorAction SilentlyContinue
- # delete any empty directories left behind after deleting old files
- Get-ChildItem -Path $path -Recurse -Force `
- | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } `
- | Remove-Item -Force -ErrorAction SilentlyContinue
- }
- Cleanup-Dir "C:\temp" 10
- Cleanup-Dir "C:\IntactStorage\Collectors\*\Backup" 14
- #Cleanup-Dir "C:\IntactStorage\Storage\Temp" 3
- #Cleanup-Dir "C:\IntactStorage\Temp" 1
Advertisement
Add Comment
Please, Sign In to add comment