Auto-Delete script

Hi Guys

I am someone can help me with a script I am trying to run. We have a shared network folder for temporary storage of documents. It is a Windows 2008 server.

Within this folder we would like to keep the size down by deleting un-modified documents which are 60 days old or older.

I had a script ready to go, but now I have checked back on it's process it is not working.

One thing about the script, I want to delete files which have not been modified in 60 days, but not the sub folders, I don't want any folder deleted.

The 2 scripts I have tried are:

dir F:\Temp_60Day_automatic_Deletion -for -rec | ? {$_.LastWriteTime -le (Get-Date).AddDays(-60) -and !$_.PsIsContainer} | del -fo


$Now = Get-Date $Days = “60” $TargetFolder = “F:\Temp_60Day_automatic_Deletion” $LastWrite = $Now.AddDays(-$days) $Files = get-childitem $TargetFolder -include *.zip, *.x86 -recurse | Where {$_.LastWriteTime -le “$LastWrite”} foreach ($File in $Files) {write-host “Deleting File $File” -foregroundcolor “Red”; Remove-Item $File | out-null}
1 answer Last reply
More about auto delete script
  1. I can't say why those scripts didn't work... not versed enough in scripting to see why they didn't. I can suggest to make sure they're being executed with adequate privileges? If that's ok, then I can only suggest creating a script using a different tool such as AutoIT3.
    Reading the drive's contents using a coupe variations of the "_FileListToArray" function, as well as the "FileGetTime" and "filedelete" commands.
    I would see it as a good few lines more than what you have above, but pretty sure it's easily doable.
Ask a new question

Read More

Management Windows Server 2008 Business Computing