HTML Report of Total Emails Sent and Received Per Mailbox in Exchange

Tzahi Kolber
3 min readOct 28, 2020

In this blog, I will review a simple PowerShell script, which generates an HTML report for the total emails sent and received per mailbox in Exchange On-Premises.

The report based on a list of mailboxes which should be created first in a simple CSV file, which later on imported by the script.
The time ranges for the total emails sent and received per mailbox at the report can be changed easily, while the default settings are the last 30 days.

The script process:

The first part of the script contains 4 parameters that can be changed inside the script to adjust it to your needs and settings:

  • The first parameter is the CSV file path and name, which contains the list of mailboxes of which you would like to get the report of:
    $ImportFile = “C:\Temp\users.csv”
    A CSV sample is attached at the end of the blog, the it looks like the next example (change only the email addresses):
  • In case you would like to export all mailboxes email address to a CSV from a specific Database, you can use the following command:

Get-MailboxDatabase DB01 | Get-Mailbox -ResultSize Unlimited | Select @{Name=’Name’; Expression={$_.PrimarySmtpAddress}} | Export-Csv -NoTypeInformation -Encoding UTF8 -Path C:\Temp\users.csv

  • The second parameter is the number of days back from the current date of which you would like to get the email report.
    The default value is 30 days back (1 month):
    $stdate = (get-date).AddDays(-30)
    In case you would like to change the default for one week for example, just change the number 30 to 7.
  • The third parameter is the end date of which you would like to get the email report.
    The default value is the current date:
    $enddate = (get-date)
  • The forth and last parameter is the HTML report file path and name, which contains the list of mailboxes and the total sent and received email during the time ranges settings.
    $ReportFile = “C:\Temp\total.htm”

The script searches the emails sent and received per mailbox based on the CSV file and using the Get-MessageTrackingLog cmd, it collects the information and rearrange it at the HTML report.

Running the script

  • Before running the script, just verify that the CSV exists at the right path, as configured inside the script (first parameter).
  • To run the script, just open the Exchange Management Shell (EMS) or from Windows PowerShell where Exchange Snapin exists and run the script.
  • The script will collect the information from all transport servers and during the data collection, a summaries of the mailbox checked with the total emails sent and received during the time ranges you have configured
  • When the script ends, an HTML report will be created at the location you have set at the beginning of the script (forth parameter):

The Script & a CSV Example

--

--

Tzahi Kolber

During the last 15 years, I was working as a Senior PFE within Exchange area at Microsoft. Now I’m Senior Consult as Azure IAAS, PowerShell & Automations.