Office 365 Mail Traffic Statistics by User

This script connects to Office 365 and retrieves the inbound and outbound mail traffic statistics by recipient for all available dates. This information is then exported to a CSV file which can be opened in Microsoft Excel.

4.7 Star
20,717 times
Add to favorites
Office 365
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Does this work with MFA enabled?
    1 Posts | Last post May 25, 2019
    • I got an error about being redirected and then Access Denied which sometimes happen because of our MFA setup.
  • Size
    1 Posts | Last post February 26, 2019
    • Hey Alan
      Thanks for great script. It worked smoothly and no changes are needed. I was just curious about output. Inbound size and outbound size is displayed in bytes or KB?
      Thanks once again.
  • Is there a way to count attachments
    1 Posts | Last post October 19, 2018
    • Can you modify your script to count attachments? I use this $MailTraffic[$Message.RecipientAddress][$MessageDate]['Attachments']++ and it doesn't work count very well
  • Needs more details
    1 Posts | Last post April 19, 2018
    • Any way to make it somewhat similar to the script on this page?
      Only interested in adding unique messages count to the report. Unique internal and external.
  • Something similar by sender?
    1 Posts | Last post February 09, 2018
    • Do you have a similar script that sorts messages by the sender, not the recipient?
  • Internal and External count?
    1 Posts | Last post November 07, 2017
    • Is there a way you can modify this script to include an external and internal report? Sent & Receive; External. Sent & Receive; Internal. 
      Thank you, 
      Patry T.
  • StartDate
    1 Posts | Last post June 02, 2017
    • Can't seem to be able to run the script with specific dates. 
      The csv file is generated but is empty
      $CurrMessages = Get-MessageTrace -PageSize 5000 -Page $Page -StartDate 04/15/2017 -EndDate 05/14/2017 | Select Received,SenderAddress,RecipientAddress,Size
  • Size
    1 Posts | Last post November 29, 2016
    • Hey Alan
      Thanks for great script. It worked smoothly and no changes are needed. I was just curious about output. Inbound size and outbound size is displayed in bytes or KB?
      I am trying to verify with few users (of course with those who have less mail send/receive items)and it is not matching.
      Thanks once again.
  • Script is failing with at last op_Addition'
    2 Posts | Last post September 30, 2016
    • Here is error
      cmdlet Get-Credential at command pipeline position 1
      Supply values for the following parameters:
      WARNING: Your connection has been redirected to the following URI:
      " "
      WARNING: The names of some imported commands from the module 'tmp_ohcxxxqp.qsm' include unapproved verbs that might
      make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the
      Verbose parameter. For a list of approved verbs, type Get-Verb.
      Collecting Recipients...
      Collecting Message Tracking - Page 1...
      Collecting Message Tracking - Page 2...
      Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
      At C:\Users\balakr\Desktop\O365Scripts\O365MailTraffic\Get-DetailedMessageStats.ps1:71 char:5
      +     $Messages += $CurrMessages
      +     ~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
          + FullyQualifiedErrorId : MethodNotFound
      Crunching Results...
      Formatting Results...
      Results saved to DetailedMessageStats.csv
    • When I run second time, there is no error.
  • Only Getting 3 Days of Data
    6 Posts | Last post September 28, 2016
    • When I run the script, it is only returning the past 3 days of information.  Sorry if this has been asked before or if this is by design, but how do you increase?
    • I was able to get the cmd to stretch to 7 days by adding the -StartDate -EndDate. Odd, I set it to 30 days but it still only pulled 7. =\
    • Where are you adding the -StartDate -EndDate?
    • You can add it here if you wish:
      Get-MessageTrace -PageSize 5000 -Page $Page -StartDate mm/dd/yyyy -EndDate mm/dd/yyyy | Select Received,SenderAddress,RecipientAddress,Size 
      Hope this helps!
    • As far as I know MessagreTrace return only 7 days. If you want to information for more that 7 days old you need to use Start-HistoricalSearch.
    • The limit for dates of returned items is 7 days, and in practice I have found that it is often less.  There appears to be a maximum combination of the values for pagesize and page.  From my experience, the value of (pagesize * page) can never go higher than 1 million.  The acceptable values are 5000 and 1000 respectively, however if you were to run the script you would see the failures happen at precisely the point where the page value reaches 201 (because 201 * 5000 is the first combination past 1 million).  I have repeated this testing using other combinations, and it's always at the point it reaches 1 million.
      The error will look something like so:
      We cannot currently process your request, please wait a few minutes and try again.
          + CategoryInfo          : InvalidOperation: (:) [Get-MessageTrace], FfoReportingException
          + FullyQualifiedErrorId : [Server=DM5PR17MB1260,RequestId=610ab2d4-2600-439d-a1be-be3020e6e537,TimeStamp=9/27/2016 2:53:42 PM] [FailureCategory=Cmdlet-FfoReportingException 
         ] 8F93CBC9,Microsoft.Exchange.Management.FfoReporting.GetMessageTrace
          + PSComputerName        :
1 - 10 of 42 Items