Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts

Search

Archives

Backup Outlook from the command line

Post image for Backup Outlook from the command line

by Steve Wiseman on April 28, 2011 · 5 comments

in Backups,BAT Files,Command Line,Exchange,Exchange 2003,Exchange 2007


.

Jennifer, sent me a question last week:

Steve,

Got a question for you. I have a small network of about 10 laptops. All of my users store their email in PST files in Outlook. I want to have an icon on their desktop that they can click to backup Outlook before they leave for the weekend. Is there any easy way to do this?

Thanks,

Jen

Yes, There is a way to do this. Now it is not foolproof, but it will work most of the time.

First, we need our script to close Outlook, that way the PST files will not be in use.

We will accomplish this with a little bit of VB Script:

Set Outlook = CreateObject("Outlook.Application")
Outlook.Quit
Set Outlook = Nothing

Save this as “CloseOutlook.vbs”

Now, we will use this script, in combination with a bat file. The bat file will run CloseOutlook.vbs, and then copy the PST files.

Most of the time PST files are located in the users AppData folder. We can use an environment variable to find this.

It is called %LOCALAPPDATA%. For our backup, we will copy it to a share named backup, and we will copy it to a folder matching the users name.

The copy command will look like this:

COPY %LOCALAPPDATA%\Microsoft\Outlook\*.pst \\server\backup\%USERNAME% /y

/y – This allows us to overwrite without being prompted.

So, we have both things that we need. The ability to close Outlook (So the user does not have to remember to do this), and a way to find and copy our PST files.

Here is what the final bat file would look like


cscript.exe CloseOutlook.vbs
COPY %LOCALAPPDATA%\Microsoft\Outlook\*.pst \\server\backup\%USERNAME% /y
@if errorlevel 1 goto ERROR_HANDLER
@goto SUCCESS
:ERROR_HANDLER
@echo "==================="
@echo "= Backup Failed =
@echo "==================="

@goto exit
:SUCCESS
@echo "==================="
@echo "= Backup Complete =
@echo "==================="

:EXIT
pause

I added an error handler, so the user will be notified if the copy could not complete.

Save it as BackupOutlook.bat and throw it on their desktop.

Now your users can backup their PST files – If they remember to do it 🙂

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 5 comments… read them below or add one }

1 X April 28, 2011 at 11:59 am

Just create a scheduled task to run the .bat file.

Still allergic to @ECHO OFF, aren’t you? 🙂

2 Stan Dunajski April 28, 2011 at 4:03 pm

You could probably setup a job in the Windows Task Scheduler on the laptops (Control Panel–>Scheduled Tasks) to run the batch file once a week.

3 Steve Wiseman April 29, 2011 at 12:27 am

That could work…but you have to make sure the scheduled task is set to run under the account of the user you are backing up – otherwise it will run as local system and nothing will get copied over.

4 Steve Wiseman April 29, 2011 at 12:28 am

I keep forgetting about that! (@echo off)

Like I said above…care needs to be taken with that, since most scheduled tasks end up running under “LocalSystem” account. This would cause the script to fail. One way around it is to run it under the account of the user that you are backing up.

5 Biswajit September 12, 2012 at 2:41 am

Thanks for your script , But need your help ….Without closing MS Outlook I want to take the PST back up. Pls help me provide a power shell script for the same!!

Leave a Comment

Category Links - Windows Forum - Exchange Forum