Determine If Distribution Group is Being Used in 365 Exchange

“What distribution groups are in use?” and “How many emails are sent to a specific distribution group per month?” are common questions I receive with 365 Exchange or Exchange.  Unfortunately, there is nothing built in that tracks how many emails on sent to a distribution group.  However we can use Get-MessageTrace to count the number of messages sent to a distribution group for a time range with the max being 30 days.  Also note, the by default PageSize returns 1000 items but you can increase the PageSize to 5000 items.  For example, to get the number of emails sent to the distribution group for a single day we can use:

Using this method, we can count the number of emails sent to each distribution group each day and store the results in an output file.  We can then query those output files and create a report.  In my example, the report will show the total emails sent to each distribution group by month and go back 12 months.  Now without further ado, let’s get to the two scripts needed.


Note: [DateTime]::Today returns 12:00 AM of the Current Date.  Let’s assume the date is currently 3/3/2016.  The script above would return the range 3/2/2016 12:00 AM to 3/3/2016 12:00 AM.  Running this script will actually return the email counts from yesterday since today has not ended.



5 thoughts on “Determine If Distribution Group is Being Used in 365 Exchange

  1. I’ve been looking for something just like this. Thank you!

    I did tweak the script some. I added code to automate the login process so that the script could be run from Task Scheduler. cred.txt has the password for an account with the privileges necessary to run the script stored in a secure encrypted string.

    #365 login creds
    $AdminName = “”
    $Pass = Get-Content “cred.txt” | ConvertTo-SecureString
    $cred = new-object -typename System.Management.Automation.PSCredential -ArgumentList $AdminName, $Pass

  2. I am so appreciative of your efforts and willingness to share your scripts. We are in a hybrid Office 365 deployment. All email accounts are in the cloud and the DLs are still on-premise. Our DLs are a hodge podge that has grown and been sorely mismanaged (i.e., ignored) for more than a decade. I needed to identify the active DLs in preparation for moving them to the cloud and address deleting the unused DLs. Your scripts are excellent and suit my needs perfectly! In just a few hours I was able to pull the last 30 days. I’ve used ChrisJ’s idea and am now setting this in Task Scheduler to continue gathering data. Thank you for your great scripts! You’ve save me a great deal of time with the deadlines I am facing!

Leave a Reply

Your email address will not be published. Required fields are marked *