Go Back   CORTEX Forums > Local Happenings > CORTEX Blogs > Random Procrastination
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Random Procrastination Darren Gosbell is a SQL Server expert and Microsoft 'Most Valued Professional' who works as a Principal Consultant at James & Monroe. His blog covers Business Intelligence, SQL Server, .Net, Powershell and MDX Madness

Reply
 
LinkBack Thread Tools Display Modes
Old 23rd June 2009, 08:30 PM   #1 (permalink)
Member
 
Join Date: Jun 2009
Posts: 27
Darren Gosbell is on a distinguished road
Thumbs up PowerShell: List all the senders from an Outlook folder

A friend of mine was looking for a tool today to extract a list of names and email addresses from a folder in outlook. I know that Outlook has a comprehensive COM based object model which I figured that I should be able to access from Powershell. I quick search turned up articles from both James Manning and Lee Holmes on automating Outlook from Powershell (which I think I have come across before). A bit of poking around using the get-member helped me locate the properties I needed and resulted in the following script.

It access the Personal\Fun folder in my inbox and exports a list of names and email addresses for anyone that has sent me a joke (or at least those which were worth keeping)
$olFolderInbox=6$ol=new-object-comobject"Outlook.Application"$mapi=$ol.getnamespace("mapi")$inbox=$mapi.GetDefaultFolder($olFolderInbox)$msgs=$inbox.Folders.Item("Personal").Folders.Item("Fun")$msgs.items |Select-Object SenderName, SenderEmailAddress -unique|export-Csv c:\emails.csv -noTypeInformation
Taking this a bit further, I wrapped this code into a script so that it could take in the path to an outlook folder and returned a collection of names and addresses.



So the following call will display the output to the console
.\get-OutlookFolderSenders.ps1 "Personal\Fun"

And to export them to a file you can just pipe through to the export-csv cmdlet
.\get-OutlookFolderSenders.ps1 "Personal\Fun" | export-csv "c:\email.csv" -noTypeInformation

Or if you want a html page you can do the following:
.\get-OutlookFolderSenders.ps1 "Personal\Fun" | convertTo-html | "c:\email.htm"*

*

I developed this little snippet of code using Powershell Analyzer which I still favour as my main Powershell IDE even though it is not longer being actively developed. It just fits with the way I like to work.






More...
Darren Gosbell is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSAS: Powershell to replace a group member in a role Darren Gosbell Random Procrastination 0 23rd June 2009 08:30 PM
IBM Outranks All Information Technology Companies on 100 Best Corporate Citizens List Latest News Headlines IBM and Cognos Forum 0 7th March 2009 10:26 PM


All times are GMT +11. The time now is 09:52 AM.

© The Business Intelligence Group

Search Engine Optimization by vBSEO 3.3.0