Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need Find and Replace Batch file to overwrite .MST files located in multiple locations

Posted on 2012-03-29
2
Medium Priority
?
433 Views
Last Modified: 2012-04-02
Request:
I need a batch file that finds a file on a user's PC and replaces it with a different file with the same name.  This would be run in a login script.

Background:

I have an organization that has a large number of legacy PC's with Office 2003.  The staff utilized the Office Customization Tool to create user's Outlook profiles when they logged onto a PC for the first time.  

The MST files has the Outlook profile point to a legacy Exchange 2003 server which needs to be decommissioned.  If the legacy Exchange 2003 server is decommissioned and a new user logs onto a machine with the old MST file on it they will be pointed to an Exchange server that no longer exists.

I need to replace the incorrect MST file with the new MST file that points the profile to the proper server.  

I cannot use (copy \\server\file share\file.mst c:\file.mst /y) due to the mst files residing under MSOCache and having different locations. The batch file will need to be able to find the MST and replace it with the updated version.

 Thank you.
0
Comment
Question by:advserver
2 Comments
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 2000 total points
ID: 37789961
Here is an idea you can try.  The more information you can provide about he mst file, the more efficient this script will run.  It will look through all files for a match (this could be time consuming) and then will copy a file from a network location to the local drive.  Make sure to update the two variables at the start with the proper information for your situation.  

' Put the pattern of the mst file match here
strPattern = "yourfilename.mst"
' Place path and location of new file here
strNewFile = "\\server\folder\newfile.mst"

strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery("Select * from CIM_Datafile where name like '%" & strPattern & "'")

For Each objFile in colFiles
	objFSO.CopyFile strNewFile, objFile.Path
Next

wscript.quit

Open in new window


-Bear
0
 
LVL 4

Author Comment

by:advserver
ID: 37795580
Thank you for your suggestion! I attempted something similar but ultimately the code below ended up working.  

dir "c:\MSOCache\File.mst" /a:-d /b /s > %TEMP%\store.txt
FOR /F "eol=; tokens=1,2,3* delims=, " %%i in (%TEMP%\store.txt) do copy \\Server\share\File.mst "%%i %%j %%k" /y
del /F %TEMP%\store.txt
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

824 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