VBS Script for System Administrators - How to backup Outlook email automatically in a login or logoff script
Posted on March 13, 2007 at 8:11 am
If you are a Systems Administrator for your company and everyone is using Outlook or some other desktop email program, you’ve probably run into the situation where someone has lost all of their emails due to the fact that it’s saved locally on the user’s computer and not on the main servers. So if you’re a small shop and can’t afford to get Exchange server, then here’s a simply way to automate the backup of user’s Outlook PST files onto your server in a login or logoff script.
First here’s the code and then I’ll explain it:
Set shell= WScript.CreateObject(”WScript.Shell”)
strUserName = shell.ExpandEnvironmentStrings(”%USERNAME%”)
Dim fso
set fso = CreateObject(”Scripting.FileSystemObject”)
lnDayOfWeek = weekday(now())
if lnDayOfWeek = 5 then
If fso.DriveExists(”G:”) Then
Dim lcDrive
Set lcDrive = fso.GetDrive(”G:”)
If lcDrive.IsReady Then
newfolderpath = “\\servername\users\” & strUserName & “\EmailBackup”
If Not fso.FolderExists(newfolderpath) Then
Set newfolder = fso.CreateFolder(newfolderpath)
End If
Dim file
file = “C:\Documents and Settings\” & strUserName & “\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst”
If fso.FileExists(file) Then
fso.CopyFile “C:\Documents and Settings\” & strUserName & “\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst”, “\\servername\users\” & strUserName & “\EmailBackup\Outlook.pst”
set fso = nothing
wscript.echo “Your email has been backed up!”
end if
end if
end If
end if
Unforunately, the code is not indented very well here, so you’ll have to copy it and fix it so that you can read it correctly. Basically, it starts off creating a FileSystem object that will take care of copying the file to the server. Then I do a check to see which day of the week it is and I use 5 (Friday), so that the script only runs once a week. I also do a check to make sure the G drive is available (the network drive I’m going to be copying the data to) before I get to the copying.
Then I check to see if the folder exists that I want to copy to and if not, I go ahead and create that folder in the user’s folder on the server. I also check to make sure the file exists and if so, I then copy it to the user’s folder on the network. I use the shell.ExpandEnvironmentStrings(”%USERNAME%”) method to get the current user’s username.
You can then apply this as either a logon or logoff script using Group Policy!
Related Posts:
More VBS Scripts for System Administrators
Office Ergonomics - Risks of working at a desktop workstation and how to avoid them
Gliffy - Online tool to create and share diagrams for free
Great tool for Help Desk/System Admintrator Professionals - Change Analysis Diagnostic tool
If you enjoyed this post, make sure you subscribe to my RSS feed!
» Filed Under IT Job Stuff
Related Posts
- More VBS Scripts for System Administrators
- Top things Windows System Administrators should and should not do!
- How to move or change the location of My Documents folder
- How to create secured Outlook data files
- How to fix slow Outlook 2003-2007 loading dataset problem
6 Responses to “VBS Script for System Administrators - How to backup Outlook email automatically in a login or logoff script”
Pingbacks
-
Backup Outlook, Outlook Express email using Amic Email backup Says:
[...] next release as Thunderbird is quite popular! I had also written a post way back about how you can write a script in Windows to automatically backup your email. Source: Ghacks Technorati Tags: email backup, backup email, backup outlook email, email backup [...]
April 9th, 2008 at 5:02 am
Please post your comments/suggestions!
[...] next release as Thunderbird is quite popular! I had also written a post way back about how you can write a script in Windows to automatically backup your email. Source: Ghacks Technorati Tags: email backup, backup email, backup outlook email, email backup [...]
April 9th, 2008 at 5:02 am
























Like your script, for home user how can I modify it to do a backup to external hard drive on a daily basis. Thanks
very useful post, i was wondering if there is code to do the same thing every night?
Many thanks
Ameneh
How can I implement when the user is log off from the system?
Is there any possible thatI could take backup of any folder on daily basis on LAN environment?
what happens if some paths contains international characters.. ?
for example c:\documents and settings\george\τα έγγραφά μου\
Need to know how to set it up to run everyday monday thur Friday. I also would like to know if I can directed to copy the users profile instead of just their pst. That is what I need to run the srcipt for thanks.