I recently made a mistake, and deleted the folder where I kept all the original headshots of all my contacts. Don’t ask me why I keep them, I just do… I know I have them in Outlook, but I like to have the originals also. Anyway, I wanted a way to export the picture from Outlook, back into the file system. Well, I ran across this script that will do just that. I could not get it to run correctly running Vista or Windows 7, running Office 2007, or Office 2010, but was able to get it to run on XP with Office 2003. Guess the MAPI calls are different or something. If anyone knows how to make this work on Windows Vista/7, using Office 2007/2010 let me know!~
Here’s the script:
Public Const CdoDefaultFolderContacts = 5snServername = wscript.arguments(0)mbMailboxName = wscript.arguments(1)set csCDOSession = CreateObject("MAPI.Session")pfProfile = snServername & vbLf & mbMailboxNamecsCDOSession.Logon "","",False,True,0,True, pfProfileset cfContactsFolder = csCDOSession.getdefaultfolder(CdoDefaultFolderContacts)set cfContactscol = cfContactsFolder.messagesset ofConFilter = cfContactscol.FilterSet cfContFltFld1 = ofConFilter.Fields.Add("0x8015",vbBoolean,true,"0420060000000000C000000000000046")For Each ctContact In cfContactscolSet collAttachments = ctContact.AttachmentsFor Each atAttachment In collAttachmentsIf atAttachment.name = "ContactPicture.jpg" Thenfname = replace(replace(replace(replace(replace((ctContact.subject & "-" & atAttachment.name),":","-"),"\",""),"/",""),"?",""),chr(34),"")fname = replace(replace(replace(replace(replace(replace(fname,"<",""),">",""),chr(11),""),"*",""),"|",""),"(","")fname = replace(replace(replace(fname,")",""),chr(12),""),chr(15),"")atAttachment.WriteToFile("c:\contactpictures\" & fname)wscript.echo "Exported Picture to : " & fnameEnd ifnextNextSave the above code as a .vbs file, and run it from the command line:
exportOutlookPic.vbs mailboxservername exchangeAlias
Make sure that you have created the folder referenced in the script, or you will get an error (c:\contactpictures\). Works like a charm! I know have all my Outlook Contact pictures, in my folder system. 🙂
