Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a /tmp folder that people use for temporary stuff. It can be anything and any file.

We want to make it so that this automatically deletes (or preferably MOVES to another folder on the same shared drive) all the files that haven't been accessed in the last two weeks. This should happen weekly on a schedule that I don't have to manually do.

Is there software out there that does this? Anyone have a script possibly?

Server 2008R2

share|improve this question
Where are you going to move the files to? Another folder? Another Windows Server? A Linux server? – cole Dec 19 '12 at 16:13
up vote 11 down vote accepted
get-childitem -Path "<location of tmp folder>" |
    where-object {$_.LastWriteTime -lt (get-date).AddDays(-15)} | 
    move-item -destination "<destination>"

This Powershell script will move the files older than 2 weeks.

share|improve this answer
+1 Pop into a tmp_clean.ps1 file, set Task Scheduler to run it every night an hour before the backup window starts. – Chris S Dec 19 '12 at 16:20
Thanks, left that part out - whoops! – cole Dec 19 '12 at 16:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.