简体   繁体   中英

Download embedded pictures-images and attachments from Outlook using Powershell

I use Windows 7 64bit, Outlook 2010, and I am looking for a powershell script to download embedded pictures and attachments from Outlook email messages.

Right now the only option is open every message and copy every picture. The email messages are in Outlook currently but I can save these off to a folder if needed.

Can someone point me in the right direction?

I wrote this small script to save attachments to a folder. tested with Outlook 2010 on Windows 8.1 x64.

$o = New-Object -ComObject outlook.Application
$ns = $o.GetNamespace("MAPI")
$f = $ns.Folders.Item(1)
$di = $f.Folders.item("Deleted Items")
$messagesWithAttachments = $di.items | Where-Object {$_.Attachments.Count -gt 0}
$messagesWithAttachments[0].Attachments.item(1).saveasfile("X:\test\picture.jpg")

It you want to save all attachments it's just a matter of looping through the messages, through their attachments and giving unique names to the files. For that you can use something like System.IO.Path.GetRandomFileName. If the file name already exists, get a new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM