Solved

Need help using Powershell to download attachments from Outlook

Posted on 2014-12-30
2
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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