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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Script to replace Outlook Signature graphics

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
ITMcmcpa
Asked:
ITMcmcpa
  • 2
  • 2
1 Solution
 
Randy DownsOWNERCommented:
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
 
Randy DownsOWNERCommented:
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
 
ITMcmcpaAuthor Commented:
Unfortunately this will not work for my needs.
0
 
ITMcmcpaAuthor 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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now