Jeremy Stein - Brain

« »

PowerShell script to archive old files

On our development server, I have all emails redirected to the file system. That directory fills up quickly, so I have a scheduled task that runs the following PowerShell hourly:

Get-ChildItem C:\MyPath -Filter "*.eml" | ?{$_.psIsContainer -eq $false -and $_.LastWriteTime -lt (Get-Date).AddHours(-4)} | Move-Item -Destination D:\MyPath\Archive

This moves any email files (*.eml) more than four hours old to the Archive directory.

March 6, 2013 No Comments.

No Comments

Be the first to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Why ask?

« »