Reputation: 11
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
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