Powershell Tip : Remove Old Backup Files

Here's a script that's very useful for me -- remove old backup files (where I'm defining old as more than a week old).
$dt = (Get-Date).AddDays(-7)
$dir = "D:\Backups"

Get-Child-Item $dir -recurse 
| where
{ $_.LastWriteTime -le $dt }
| foreach
($_)
{remove-item $_.fullname -whatif}
Note that you'll want to remove the "-whatif" to actually delete the files, rather than just show them in a test mode!

Posted on 5/3/2009 7:11:51 AM by Jason Nadal

Permalink | Comments |

Categories:

Tags:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
blog comments powered by Disqus