Windows 2000/2003 Batch file variables / wildcards

Server: Windows 2000 and 2003; clients: Windows 2000 Pro and XP Pro

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 their local computers (the pst files are for OL2003 and can't be on the server-performance issues). 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 <variable> are the places where I need wildcards/variables:

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.

%computername% = The name of the computer on which the file is being run.
%username% = the name of the user that is currently logged in.

So you could change your script to look like this:
@ECHO off
xcopy /e /v /y \\%computername%\c$\documents and settings\%username%\local settings\application data\microsoft\outlook\*.pst \\serverv\users\%username%\outlook_backup

The difficulty with this, is it will only work with the user that is currently logged in, it won't search for other profiles.

Will this work for you, or do you need it to scan for pst files under other profiles too?

Bartender_1

0

CathylbAuthor Commented: 2007-03-21

That certainly is a step closer and if need be, it would work. I do have a few PCs that house two or more profiles with active Outlook files. However, when the second user logs on, works, and then logs off, their file would get backed up, so perhaps this will work. I'm at home now, but I can experiment with this solution at work tomorrow or Friday. Thank you!

I figured that might be the best solution for you, because if you need it to scan other profiles, you could run into permissions issues accessing the files to back them up. This way, you know the user logged in has permissions to their own files so you can keep that out of the mix.

Actually, I want to avoid having to do anything from the user station - I want all of this to be done on the server. Otherwise, it gets very cumbersome having to go to each machine and enter a policy. I'm a one-woman show running five networks in five locations. I will let you all know how this worked out.

I thought you did too, but then you said:
"I want to avoid having to do anything from the user station"

Logoff scripts execute on the users station...

0

CathylbAuthor Commented: 2007-03-21

Okay, what I meant was I want to avoid having to physically go to each user station and enter configurations. Sorry for the misunderstanding. I know that the log off script executes at the user station, just like my log on script does. Thanks for clearing it up for others, though.

0

CathylbAuthor Commented: 2007-03-23

When I tested this script, my server came back with a "UNC PATHS ARE NOT SUPPORTED."
As far as the users directory, no problem, I just direct it to E:\users\%username&\ etc.

But, the tricky part is, without using a UNC path, how do I direct the script to each of my users' local computer where the file is located that it is copying to the server? Do I have to map a drive to every computer? How is this done? Help...

0

CathylbAuthor Commented: 2007-03-23

Follow up to my last message: Here is the batch file I am using on my Win 2000 server:
----------------------------
@ECHO off

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

xcopy \\%COMPUTER%\c$\documents and settings\%USERPROFILE%\local settings\application data\microsoft\outlook\*.pst /e /v /y \\server\users\%USERNAME%\outlook_backup
---------------------------
The only success I am having is that it IS executing (so I have the GP set up properly), but it is ONLY making the directory, it is not executing the xcopy command (yes xcopy.exe does exist on the server and the client).

leew is correct,
The environment variable %userprofile% automatically maps to the location of the users profile. (In case you have a setup that doesn't follow defaults of "C:\Documents and Settings\<username>") It does not have anything to do with Active Directory.

The script that leew is suggesting should work for you just fine.

The script I suggested will work on systems with the default installation paths, but the script suggested by leew, would account for setups that don't follow the default installations.

0

CathylbAuthor Commented: 2007-03-26

Thank you, both!

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"