[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBS to clear out UCEArchive

Posted on 2007-09-29
5
Medium Priority
?
826 Views
Last Modified: 2008-07-11
I would like a VBS that can look at a certain directory and delete files created over a week ago.

This will run once a day (as a scheduled task preferably) to look at my Exchange Server's UCEArchive folder - where suspect spam mail is stored - and delete any files in that folder which were created over a week ago. I need this grace period between mail going in there and being deleted so we can retrieve it if it was legitimate.

Thanks in advance
0
Comment
Question by:tigermatt
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
chandru_sol earned 1000 total points
ID: 19984569
Hi,

Can you try  the below script? Please change the folder location

Dim oFSO
Dim oFolder
Dim oFile
Dim iDaysOld

'Customize values here to fit your needs
      iDaysOld=7
      Set oFSO=CreateObject("Scripting.FileSystemObject")
      set oFolder=oFSO.GetFolder("C:\Scripts\logss")

'Walk through each file in this folder collection.
'If it is older than 7 days, then delete it.

For each oFile in oFolder.Files
If oFile.DateLastModified < (Date() - iDaysOld) Then                               
oFSO.DeleteFile oFolder.Path & "\" & oFile.Name
End If
Next

'Clean up
      Set oFSO = Nothing
      Set oFolder = Nothing
      Set oFileCollection = Nothing
      Set oFile = Nothing

regards
Chandru
0
 
LVL 58

Author Comment

by:tigermatt
ID: 19984591
That's brilliant, thank you. (Points increased as I have another question below)

How do I make it run as a scheduled task? Can I use the following command?
%windir%\system32\cscript.exe "N:\My Settings\Desktop\ucearchive cleaner.vbs"

Thanks
-tigermatt
0
 
LVL 12

Assisted Solution

by:chandru_sol
chandru_sol earned 1000 total points
ID: 19984641
Hi Tigermatt,

You can select the file directly in the scheduled task and there is no command required

Please try and let me know

regards
Chandru
0
 
LVL 58

Author Comment

by:tigermatt
ID: 19984782
Brilliant,

thanks Chandru
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 19984868
Glad I am of help!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question