vbs script
----
Automatically Remove Files Older Than ‘X’ Days
Tape backups have failed me too many times, so I now do my Windows backup to an external hard drive. One of the office staff is in charge of swapping out our backup drives and taking it offsite. I needed a solution that would remove old backups without user intervention so they wouldn’t have to worry about having enough space available for the backup to complete.
My hard drives can hold four backups, so here’s a very simple .vbs script that deletes files from I:\Backup Files that are more than three days old:
Dim FsoDim DirectoryDim ModifiedDim FilesSet Fso = CreateObject("Scripting.FileSystemObject")Set Directory = Fso.GetFolder("I:\Backup Files")Set Files = Directory.FilesFor Each Modified in FilesIf DateDiff("D", Modified.DateLastModified, Now) > 3 Then Modified.DeleteNext
Save this as filename.vbs. To execute this file, run:
cscript.exe filename.vbs
Thanks to Don for the original script I modified for my particular needs.
[updated 01-02-2008]
This script from the Scripting Guy deletes files ‘X’ number of hours old. Looks like it could be modified easily to meet your needs.
Script to Gracefully Close an Outlook .PST File So It Can Be Backed Up
I was listening to the latest episode of the Casting from the Server Room podcast this morning, and one of the discussions was about backing up an Outlook .pst when users leave Outlook open overnight, which is when the backup is scheduled to run.
In order to back an Outlook .pst file, the .pst file must not be in use. The easiest way to make sure the .pst file isn’t in use is to close Outlook on the computer the .pst resides on.
I found this .vbs script, written by Bill Stewart, on Chris’s blog that will close Outlook gracefully.
On Error Resume Next Set Outlook = GetObject(, "Outlook.Application") If Err = 0 Then Outlook.Quit() End If
Just killing Outlook can result in .pst corruption, so I don’t suggest using a program like pskill to terminate outlook.exe.
Bill also has an Exchange version of the above script, which can be downloaded here.
You can schedule these scripts to run nightly with a Windows Scheduled Task, or with a program like psexec, which will execute programs on remote machines through a command line or script.
---