Solved

Script to replace Outlook Signature graphics

Posted on 2011-03-09
6
178 Views
Last Modified: 2014-01-01
Hello,

I need a script that will look for a specific file in subfolders based on name and size and replace it with another file.

Here is the task:

We have to change a graphic on our Firm's Outlook signature block.  I want to run a script on each computer (maybe via login script) that will search all signature folders and it's subfolders under %appdata%/Microsoft/Signatures and replace the file image003.gif that has a size of 2470 bytes.  We will replace it with another file called image003.gif copied from another network location.

Thanks!
0
Comment
Question by:ITMcmcpa
  • 2
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Randy Downs
ID: 35083627
Try this - http://www.myitforum.com/articles/40/view.asp?id=9571
This script will find a file on C drive (or whatever drive we choose), rename it and replace it with another file. The new file should be in the same directory where you execute your powershell script.


#Because of CIM_DataFile, split File Name and Extension into two variables
$strFileName = "Foo"
$strFileExt = "doc"
$strNewFileName = "Foo2.doc"

$colFiles = get-wmiobject -query "Select * from CIM_Datafile where FileName = '$strFileName'and extension = '$strFileExt' and drive ='C:'"
Foreach ($objfile in $colfiles)
{
Ren $objfile.name -newname ($objfile.filename +".bak")
copy-item $strNewFileName -destination ($objfile.drives + $objfile.path)
}
0
 
LVL 29

Expert Comment

by:Randy Downs
ID: 35083674
You might need to copy the replacement file to the local drive to use the above script.
http://www.remotedatabackups.com/kb/kb.cfm?id=63
0
 

Author Comment

by:ITMcmcpa
ID: 35083823
Unfortunately this will not work for my needs.
0
 

Accepted Solution

by:
ITMcmcpa earned 0 total points
ID: 35094442
We searched some of our old scripts and found one that would work "good enough".  It doesn't cycle through all of the subfolders but it will update 99% of our users.  We can update the remaining manually.

 
Option Explicit 
Dim FSO,File
Dim gifsize
Dim gifsize2
dim CurrentFile
dim path
dim ws
dim fullpath
dim FindNewFileSize


Const OverwriteExisting = True


newfile =  "\\srv-file01\Vol6\install\ScrResources\signatureoffices\image003.gif"


'file size of existing gif to replace
gifsize = 2470

path="%appdata%"

Set ws=CreateObject("WScript.Shell")

fullpath= ws.ExpandEnvironmentStrings(path)

'Get the information regarding the currentfile
 currentfile = fullpath & "\Microsoft\Signatures\MCM_Files\image003.gif"
 set FSO=CreateObject("Scripting.FileSystemObject")

If (fso.fileexists(currentfile)) then  'only runs if the file exists

Set File=FSO.GetFile(currentfile)
Set FindNewFileSize =FSO.GetFile(newfile)


gifsize2 = File.Size



if gifsize2 = gifsize then

FSO.CopyFile newfile , currentfile , OverwriteExisting

end if

end if

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

821 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