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...