Solved

Need help using Powershell to download attachments from Outlook

Posted on 2014-12-30
2
401 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 69

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
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…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

808 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