Geeks With Blogs


View Tarun Arora's profile on LinkedIn

profile for Tarun Arora at Stack Overflow, Q&A for professional and enthusiast programmers

Tarun Arora - Visual Studio ALM MVP ALM, Agile, Automation, Performance Testing, Software QA, Cloud, ...

I promised my friend Chuck that I would post the Power Shell script to get the list of most discussed topics and the tops writers in an email distribution list. Generally there are loads of emails that fly around on the ALM Champs and ALM Rangers distribution list. It is interesting to analyse what are the most discussed topics are and who are the most active participants. More details on the objective here on Chuck’s blog.

So, here we go, the powershell script below will give you the following output,

  • Return a count of emails by subject
  • Return a count of emails by sender

The PowerShell Script

$FolderToAnalyse = "ALM Champs"
$ReceivedAfter = "1/Mar/2013"

# Access Outlook using Powershell
$GetOutlook = New-Object -com "Outlook.Application";
$olName = $GetOutlook.GetNamespace("MAPI")

# Get All folders
$olxEmailFolder = $olName.GetDefaultFolder(‘olFolderInbox’)

ForEach($Folder in $olxEmailFolder.Folders)
    # Analyse the folder of choice
    if($Folder.Name -eq $FolderToAnalyse)
        # Filter to emails for the specified period
        $emails = $Folder.Items | Where-Object {$_.ReceivedTime -gt $ReceivedAfter}
        # Group Email by Subject and output in descending order
        $emails | Select Subject | Group-Object Subject -NoElement | Sort-Object Count -Descending | ogv

        # Top Writers
        $emails | Select SenderName | Group-Object SenderName -NoElement | Sort-Object Count -Descending | ogv

Write-Output Completed




  • You can pass the name of the outlook folder you would like to analyze using the variable $FolderToAnalyse, the date from which you would like to analyse emails can be specified in the variable $ReceivedAfter.
  • Essentially the script is pulling a list of all outlook folders and selecting the folder you passed in the variable $FolderToAnalyse, it narrows down the emails in this folder to the date period specified by you in the variable $ ReceivedAfter.
  • Pipe the shortlisted emails to group by the email subject. Pass the object to the powershell grid view for output.
  • Pipe the shortlisted emails to group by the sender name. Pass the object to the powershell grid view for output.
  • Notice that I am using -NoElement with Group-Object, reason, I don’t want the group by output to be printed in an additional column, using the -NoElement switch omits this from the grid view.


As you run the script, you might be prompted by Outlook to allow access by PowerShell to your outlook folder in question. Choose Allow and you should see two separate grids pop up with the output of most discussed emails and top contributors. Since this is the PowerShell grid view, you can use the filter menu to reduce the noise by specifying a filter.



You can not only filter but also export the results out. Learn more about the capabilities of the Powershell out grid view.

Hope you find it useful! :-]




Posted on Sunday, March 3, 2013 11:41 PM Power Tools , PowerShell | Back to top

Comments on this post: Power Shell Analysing Emails Trends

comments powered by Disqus

Copyright © Tarun Arora [Microsoft MVP] | Powered by: