Question Locked

Windows 2000/2003 Batch file variables / wildcards

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am writing a batch file to copy a *.pst file from user machines to the server upon user logoff.

The location of the *.pst file will be the same for each profile of each user on the computer. I don't know how to put wildcards or variables in. I don't want to have to write a batch file for each user - I want one file that works for all.

Here is what I have so far. Where I have put are the places where I need wildcards/variables:

@ECHO off
xcopy /e /v /y \\\c$\documents and settings\\local settings\application data\microsoft\outlook\ \\serverv\users\\outlook_backup

On some of my machines I have more than one profile with a *.pst file to be copied. I want it to basically check all profiles and copy them

What are the variables or wildcards I could use so that I can write one batch file that would work for all users? The file will be placed in domain policy/user configuration/log off on my 2000 or 2003 servers.

Thanks, everyone -

Cathy
Maine

11 replies

by rkuhn040172

Give each user their own folder on a server and then map it?

Or use folder redirection? Most .pst are stored in My Documents...do folder redirection for My Documents and then backup all their "important" files.

by cburnham

Because this is Outlook 2003. Outlook 2000 was fine with the pst files on the server - I've done that for years. However, with OL2003, pst files being accessed via a network slow down to a crawl (I've run tests). So I need help with this batch file. Thanks anyway.

by bizzo

If you're running the batch file from the local machine, then this shouldn't be too difficult.
If you open a command prompt, and type set, this will list the environment variables for the user. Where you have COMPUTERNAME, USERNAME, USERPROFILE etc. Surround the variables with %, to have them expand in the batch file.

So if you run the batch locally, the copy command should look something like this:

xcopy /e /v /y %USERPROFILE%\local settings\application data\microsoft\outlook\*.pst \\serverv\users\%USERNAME%\outlook_backup\.

Hope this helps.

by cburnham

I made it clear in my original post that this is running from the server. I do not want to have to configure 40 user machines. Thanks, anyway.

by bizzo

If you add the copy command to the logoff script, it will run locally, and so will pick up the environment variables for the current user.

by Member 25348569

Useful ones that are present if you run this script as the logged-in user on that user's workstation:

%USERNAME% gives the login name
%COMPUTER% gives the local PC name
%USERPROFILE% will point to the active profile. i.e. C:\Documents and Settings\user.name

xcopy /e /v /y "%USERPROFILE%\local settings\application data\microsoft\outlook\*.pst" \\serverv\users\%USERNAME%\outlook_backup

would work although it would assume that the target folder exists.

You could add (at the front)

If not exist "\\serverv\users\%USERNAME%\outlook_backup" md "\\serverv\users\%USERNAME%\outlook_backup"

by cburnham

The batch file is not copying my files. It DOES make the directory, so I know my group policy is working. When I manually run the batch file, I get a message saying "UNC PATHS ARE NOT SUPPORTED." When I researched this I found info that said that the file should still run. But, it isn't. Thoughts?

by bizzo

Could you post the part of the script that's causing trouble?

by cburnham

Between you guys here at TechRepublic and the guys at Experts Exchange, I finally have a working script. So, I am posting it here for others in the hopes that someone else will find it useful.

This is a batch file that successfully copies the PST file from a client to the server. If the outlook_backup folder does not exist, it creates it:

@echo off

If not exist "\\augserv\users\%USERNAME%\outlook_backup" md "\\augserv\users\%USERNAME%\outlook_backup"

xcopy /e /c /h /o /v /y "%userprofile%\local settings\application data\microsoft\outlook\*.pst" "\\augserv\users\%username%\outlook_backup"

Thanks, everyone, for your help.

Cathy
Maine

This discussion is closed to new replies.