Export Outlook Contact Pictures

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 = 5
snServername = wscript.arguments(0)
mbMailboxName = wscript.arguments(1)
set csCDOSession = CreateObject("MAPI.Session")
pfProfile = snServername & vbLf & mbMailboxName
csCDOSession.Logon "","",False,True,0,True, pfProfile
set cfContactsFolder = csCDOSession.getdefaultfolder(CdoDefaultFolderContacts)
set cfContactscol = cfContactsFolder.messages
set ofConFilter = cfContactscol.Filter
Set cfContFltFld1 = ofConFilter.Fields.Add("0x8015",vbBoolean,true,"0420060000000000C000000000000046")
For Each ctContact In cfContactscol
	Set collAttachments = ctContact.Attachments
	For Each atAttachment In collAttachments
		If atAttachment.name = "ContactPicture.jpg" Then
			fname = 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 : " &  fname
		End if
	next
Next

Save 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. :)

Related posts:

  1. Export Outlook Contact Pictures
  2. More IMAP / Outlook 2007 Tweaks
  3. Finally! Microsoft Outlook 2007 Sidebar Gadgets!
  4. IMAP in Outlook 2007 Speed Tweaks
  5. 2-way Syncing: Google Calendar / Outlook (Finally!)
This entry was posted in Microsoft, Outlook, Scripts. Bookmark the permalink.

5 Responses to Export Outlook Contact Pictures

  1. Hank says:

    Here is some code to get all the photos from an Outlook 2003 address book and dump it in a folder. Just stick it in a Macro in Outlook and run — though you may get some errors if you have other types of attachments in your Contacts and may have to handle those exceptions:

    Sub GetPix()
    Dim myNamespace As Outlook.NameSpace
    Dim itemContact As ContactItem
    Dim fdrContacts As MAPIFolder
    Dim colAttachments As Outlook.Items
    Dim colItems As Outlook.Items
    Dim myProperty As Outlook.UserProperty
    Dim fname As String

    Set myNamespace = Outlook.GetNamespace(“MAPI”)
    Set fdrContacts = myNamespace.GetDefaultFolder(olFolderContacts)

    For itemCounter = 1 To fdrContacts.Items.Count

    Set itemContact = fdrContacts.Items(itemCounter)
    Set collAttachments = itemContact.Attachments

    For Each atAttachment In collAttachments

    If atAttachment.FileName = “ContactPicture.jpg” Then

    fname = Replace(Replace(Replace(Replace(Replace((itemContact.FirstName & itemContact.LastName & “-” & atAttachment.FileName), “:”, “-”), “\”, “”), “/”, “”), “?”, “”), Chr(34), “”)

    fname = Replace(Replace(Replace(Replace(Replace(Replace(fname, “”, “”), Chr(11), “”), “*”, “”), “|”, “”), “(“, “”)

    fname = Replace(Replace(Replace(fname, “)”, “”), Chr(12), “”), Chr(15), “”)

    atAttachment.SaveAsFile (“c:\AA-Exporting\” & fname)

    End If

    Next

    Next

    End Sub

  2. Nerd says:

    Thanks Hank! That’s a really nice way to do it too! Thanks for sharing!

  3. Norman says:

    Thx for sharing this great stuff !
    In an exchange/outlook workaround it works very fine.

    My question is: How can i do this in a outlook standalone version (pop/smtp)? What is there “mailboxservername” and “exchangeAlias” ?

    Greets

  4. Nerd says:

    That’s a good question – Let me see if I can find out how to extract them from a PST file instead of from an exchange server…

  5. Neurotico says:

    Were you ever able to find the code or script that works with Win 7 & Outlook 2010? I have been google’ing and this is the only page I found that has a way to export images with the contacts.

    I actually want to export all my contact data (names, emails, images, etc), then import to Gmail…the google apps sync scares me to configure on my DC (I’m the domain admin) since all I want to do is sync my contacts once, then uninstall the app…too much work to get that working in a domain behind a proxy. It is an exchange environment that I will be exporting the contacts from…but you mentioned it does not work with Win 7 or Outlook 2010 (I am running both).

    Although a long work-around for me could be to load up Win-XP Mode, install Office ’03, connect it to my exchange mailbox, let it sync the contacts, then run the script. I will do this if there is not a way yet with Outlook 2010.

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>