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

Closed
shubh25 Posts 2 Registration date Monday November 26, 2012 Status Member Last seen November 26, 2012 - Nov 26, 2012 at 01:13 AM
shubh25 Posts 2 Registration date Monday November 26, 2012 Status Member Last seen November 26, 2012 - Nov 26, 2012 at 01:16 AM
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

shubh25 Posts 2 Registration date Monday November 26, 2012 Status Member Last seen November 26, 2012
Nov 26, 2012 at 01:16 AM
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...!
0