Solved

Need help using Powershell to download attachments from Outlook

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

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

Suggested Solutions

Title # Comments Views Activity
How to send PowerShell result by email? 8 55
Problem with Yahoo and Outlook SMTP Email 7 72
exchange, outlook 8 57
exchange, outlook 2 21
If you don't know how to downgrade, my instructions below should be helpful.
A procedure for exporting installed hotfix details of remote computers using powershell
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 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: …

911 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

19 Experts available now in Live!

Get 1:1 Help Now