Solved

Script to replace Outlook Signature graphics

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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