Solved

Script to replace Outlook Signature graphics

Posted on 2011-03-09
6
175 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

16 Experts available now in Live!

Get 1:1 Help Now