Solved

Windows 2000/2003 Batch file variables / wildcards

Posted on 2007-03-21
18
643 Views
Last Modified: 2013-12-05
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:

@ECHO off
xcopy /e /v /y \\<variable-computer name>\c$\documents and settings\<variable-profilename>\local settings\application data\microsoft\outlook\<variable.pst> \\serverv\users\<variable-user name>\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
0
Comment
Question by:Cathylb
  • 9
  • 5
  • 4
18 Comments
 
LVL 22

Assisted Solution

by:Bartender_1
Bartender_1 earned 62 total points
Comment Utility
There are environment variables that could be used in this situation

Environment variable and what they are for:

%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
 

Author Comment

by:Cathylb
Comment Utility
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!
0
 
LVL 22

Expert Comment

by:Bartender_1
Comment Utility
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.

Hope this works for you.

:o)

Bartender_1
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
Get Exchange.  MUCH simpler and more effective mail backup.

That said, I assume you are executing the XCOPY command from the local workstation that the user has been logged in to... in which case, I would recommend using this line instead:

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

0
 

Author Comment

by:Cathylb
Comment Utility
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.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
You're not putting this in as a logout script in active directory?  That's where this should be run - YOU personally need not go anywhere, just put the script into place.
0
 

Author Comment

by:Cathylb
Comment Utility
Exactly. Yes, this is all being done from the server, from Active Directory, in a Domain Policy/User Configuration/log off. I believe I explained this in my original post.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
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
 

Author Comment

by:Cathylb
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Cathylb
Comment Utility
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
 

Author Comment

by:Cathylb
Comment Utility
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).

Is my syntax wrong?

Cathy
0
 
LVL 22

Expert Comment

by:Bartender_1
Comment Utility
Instead of %computer% try using %computername%
You also should enclose the path in quotes to avoid difficulties with spaces in the path.

Another thing you could try if you're having difficulties connecting to the UNC, is having the script map a drive letter before executing the script and then removing the drive mapping afterwards.

net use z: \\server\users
xcopy "c:\Documents and Settings\%username%\local settings\application data\microsoft\outlook\*.pst" "z:\%username%\outlook_backup" /e /v /y
net use z: /delete



Hope this helps!

:o)

Bartender_1
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 63 total points
Comment Utility
I'm wondering why you've ignored my comment which basically says don't do this:

xcopy \\%COMPUTER%\c$\documents and settings\%USERPROFILE%\local settings\application

And DO do this:
xcopy /e /c /h /o /v /y "%userprofile%\local settings\application data\microsoft\outlook\*.pst" "\\serverv\users\%username%\outlook_backup"




Notice the differences?
0
 

Author Comment

by:Cathylb
Comment Utility
Bartender_1: I will try your suggestions on Monday at work.

Leew - Does that script copy from the user's local computer to the server? It looks to me like it assumes I'm using roaming profiles (which I am not). Can you explain, please?
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
Of course it does - it uses the environment variable defining the location of the user's profile - roaming profiles is defined in active directory... this has nothing to do with romaing profiles.

Try it, you'll see.
0
 

Author Comment

by:Cathylb
Comment Utility
Okay, I will - thank you very much, Leew and Bartender_1. I'll report back on which solution works.
0
 
LVL 22

Expert Comment

by:Bartender_1
Comment Utility
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
 

Author Comment

by:Cathylb
Comment Utility
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"

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Know what services you can and cannot, should and should not combine on your server.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now