Script to replace Outlook Signature graphics


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.

Who is Participating?
ITMcmcpaConnect With a Mentor Author Commented:
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


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

Randy DownsOWNERCommented:
Try this -
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 $ -newname ($objfile.filename +".bak")
copy-item $strNewFileName -destination ($objfile.drives + $objfile.path)
Randy DownsOWNERCommented:
You might need to copy the replacement file to the local drive to use the above script.
ITMcmcpaAuthor Commented:
Unfortunately this will not work for my needs.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.