Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
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 '12 at 16:20
    
Thanks, left that part out - whoops! –  cole Dec 19 '12 at 16:22
add comment

Your Answer

 
discard

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.