Solved

Need help using Powershell to download attachments from Outlook

Posted on 2014-12-30
2
335 Views
Last Modified: 2014-12-30
I want to save attachments from emails located in a particular Outlook folder,  I've found several examples and am able to get to the folder I want but then I get lost.  

When try to access something simple from the folder like the count it gives me a value that does not represent that folder but rather the inbox.  When I try to print out something like the subject etc.. I get System.__ComObject.  

There is something very basic that I  do not understand, can anyone help get me on the right track??Get-OutlookFoldersv2.txt

Thanks
0
Comment
Question by:c7c4c7
2 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40524676
Parts of the code are superfluous and cumbersome, but that is probably caused by you trying out things. E.g. you do not need the Interop.Outlook assembly, at least for the shown part of your code.
This should be all you need for getting basic info about unread mails in Daily Reports:
$olApp = New-Object -com "Outlook.Application";
$olFolder = $GetOutlook.Session.GetDefaultFolder(‘olFolderInbox’).Folders.Item('Daily Reports')
$unread = $olFolder.Items.Restrict('[Unread] = true')

Write-Host "# of unread mails $($unread.count)"
$unread | Select-Object Subject, ReceivedTime, Importance, SenderName

Open in new window

Attention, if you have something invalid in the Restrict, like you had with "[UnRead] = 'True'", then you get the same results as if you check against false - all read mails. The true does not belong into quotes.

Next important point with COM object and Office Automation in PowerShell: You always get System._ComObject as type, so nothing really useful here. If you need details, look up the expected object type in Outlook or Excel or ... online help for objects. E.g. the mails are MailItem objects, the online help is at http://msdn.microsoft.com/en-us/library/office/ff861332(v=office.15).aspx .
0
 

Author Closing Comment

by:c7c4c7
ID: 40524995
That's a whole lot easier than the way I was doing it and it got the right folder

Thanks for the help
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now