Script to clean up windows virtual server temp folder 1 hr old

[Closed]
Report
Posts
2
Registration date
Monday November 26, 2012
Status
Member
Last seen
November 26, 2012
-
Posts
2
Registration date
Monday November 26, 2012
Status
Member
Last seen
November 26, 2012
-
Hello,


Our Clients using the windows virtual box always have issues with low disk space due to temp files not getting cleaned up by application in various circumstances.

Goal is to put the windows shell script together that would run every one hour through task scheduler to remove files from the temp directory over one hour old.

It would be really helpful, If someone can provide a script, which can delete the files older than one hour.

Thanks in advance...!

1 reply

Posts
2
Registration date
Monday November 26, 2012
Status
Member
Last seen
November 26, 2012

Few of them i tried were

@echo off
cd /d "%temp%"
rd /s /q "%temp%"

But its deleting each and every file, wasn't able to find an option in scheduler to delete one hour old files.

Other script:

dir c:\temp |
?{-not $_.PsIsContainer} |
?{$_.CreationTime -lt [datetime]::Now.AddHours(-1)} |
%{Remove-Item $_ -WhatIf}

Unsure, whether it needs some more customization...its not running at all...!