Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows 2000/2003 Batch file variables / wildcards

Posted on 2007-03-21
18
Medium Priority
?
656 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
18 Comments
 
LVL 22

Assisted Solution

by:Christopher McKay
Christopher McKay earned 248 total points
ID: 18767992
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
ID: 18768025
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:Christopher McKay
ID: 18768041
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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 18768165
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
ID: 18768427
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 96

Expert Comment

by:Lee W, MVP
ID: 18768444
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
ID: 18768470
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 96

Expert Comment

by:Lee W, MVP
ID: 18768496
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
ID: 18768559
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
 

Author Comment

by:Cathylb
ID: 18781450
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
ID: 18781978
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:Christopher McKay
ID: 18783357
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 96

Accepted Solution

by:
Lee W, MVP earned 252 total points
ID: 18784529
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
ID: 18785091
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 96

Expert Comment

by:Lee W, MVP
ID: 18785195
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
ID: 18786221
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:Christopher McKay
ID: 18786244
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
ID: 18792399
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 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