Nishant Fukate
Nishant Fukate

Reputation: 11

Download email attachments from outlook using powershell

I am using following code to download outlook email attachments and images to folder. But it is throwing an error: Cannot index into a null array.

Any guess why?

$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("C:\test")

Upvotes: 0

Views: 119

Answers (1)

Sid
Sid

Reputation: 2676

Provided there are emails with attachments, give a filename instead of folder in the saveasfile() method.

Eg: saveasfile("C:\test\test.txt")

Upvotes: 0

Related Questions