?
Solved

Need help using Powershell to download attachments from Outlook

Posted on 2014-12-30
2
Medium Priority
?
615 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 71

Accepted Solution

by:
Qlemo earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Changing a few Outlook Options can help keep you organized!
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
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…
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.

650 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