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

  • Where are you going to move the files to? Another folder? Another Windows Server? A Linux server? Dec 19, 2012 at 16:13

1 Answer 1

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.

  • 4
    +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, 2012 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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