Total Emails Sent and Received Per Day and Size

This script counts the number of e-mails and their size that are sent and received in your Exchange environment per day.

 
 
 
 
 
4.8 Star
(21)
23,355 times
Add to favorites
Exchange
11/17/2016
E-mail Twitter del.icio.us Digg Facebook
  • Dont work Exchange 2010
    2 Posts | Last post February 26, 2019
    • Exchange 2010
      
      The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
      
    • PS C:\1> .\TotalEmailsSentReceivedPerDay.ps1
      DayOfWeek,Date,Sent,Sent Size (MB),Received,Received Size (MB)
      The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
          + CategoryInfo          : InvalidArgument: (SVRCAS:PSObject) [Get-MessageTrackingLog], ParameterBindingException
          + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
          + PSComputerName        : svrcas.domain
  • How to repurpose using an input file to run this query per mailbox?
    1 Posts | Last post January 02, 2019
    • I have used a "ForEach" loop to read email addresses from a csv file and passing them to the "Do...While" statement (finding stats per user using two Get-MessageTracking queries).  This method only performs the "Get-MessageTracking" data gather process on the first user run.  Can you provide any feedback as to why this is occurring and if there may be a work around?
  • Invalid cmdlet for Exchange 2010
    2 Posts | Last post October 02, 2018
    • When running this in Exchange 2010 shell, I get the following errors:
      
      The term 'Get-TransportService' is not recognized as the name of a cmdlet, function, script file, or operable program.
      Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      At F:\PowerShell Files\TotalEmailsSentReceivedPerDay.ps1:23 char:26
      +     (Get-TransportService <<<< ) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach {
          + CategoryInfo          : ObjectNotFound: (Get-TransportService:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
      
      
      Exchange 2010 shell doesn't have the Get-TransportService cmdlet. Any recommendations?
      
      Thanks,
      Curtis
    • @Curtis
      You need to at the MSExchangeTools to your ps-script.
      
      Like:
      Add-PSSnapin microsoft.exchange.management.powershell.e2010
  • What if the servers are more than one.
    8 Posts | Last post February 03, 2017
    • Hi Nuno, 
      I can see I asked a question in Aug 2015. 
      What is the situation today:
      - If I run just Get-TransportService I get a table of two columns. The first column is "Name", and has the names of our 4 servers,  the second column is "MessageTrackingLogEnabled" and all the 4 values it contains are $True.
      - If I remove Get-TransportService from your original script it runs for some time apparently querying only one of the servers. 
      Q1: To get a complete result for our University, is that enough or should I query all 4 servers and finally sum the results?
      
      - If I run your original script without any changes I get the following error:
      
      The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do
      not match any of the parameters that take pipeline input.
          + CategoryInfo          : InvalidArgument: (server1:PSObject) [Get-MessageTrackingLog], ParameterBindingException
          + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
          + PSComputerName        : server1.ourdomain.ca
       
      It repeats 4 times for each day of the period, for each of the 4 servers. Above I replaced the real 
      name of our server with "server1" and also replaced the FQDN with server1.ourdomain.ca
      
      Please advise, how to proceed
      Thank you, 
      Mario
      
    • Hi Mario,
      
      To query all servers and get a complete set of results, you need to always run "Get-TransportServer | Get-MessageTrackingLog (...)" or "Get-TransportService | Get-MessageTrackingLog (...)" if you are running Exchange 2013/2016. Don't worry about what Get-TransportService returns, the Get-MessageTrackingLog will take care of accepting it as input.
      Are you running the exactly exactly as is, or did you change anything?
      
      Regards,
      Nuno
    • Hi Nuno,
      Yes, I just confirmed again.
      Absolutely not edited script, just downloaded as is - throws errors for each day, for each transport server as I already reported.
    • OK, I found it. Apparently Get-MessageTrackingLog (...) doesn't like the object(s) passed to it.  All starts running normal by just one single edit in your original script:
      (Get-TransportService)
      to become
      (Get-TransportService).name
      
      It is interesting if this is a version problem. We have Exchange 2013 and $PSVersionTable is:
      
      Name                           Value
      ----                           -----
      PSVersion                      3.0
      WSManStackVersion              3.0
      SerializationVersion           1.1.0.1
      CLRVersion                     4.0.30319.18449
      BuildVersion                   6.2.9200.16628
      PSCompatibleVersions           {1.0, 2.0, 3.0}
      PSRemotingProtocolVersion      2.2
      
      
      Thanks for the nice script!
      Mario
    • Hi Mario,
      
      Thank you for the update. That is really strange... I have been using this method since Exchange 2007, in many different environments and never had that problem... Can you try "Get-TransportService | Get-MessageTrackingLog" instead of "(Get-TransportService) | Get-MessageTrackingLog"? Thanks.
      
      Regards,
      Nuno
    • Hi Nuno,
      I confirm, if I just remove the brackets in the script I get the same error. 
      
      To make the experiment simpler, I tried just in the console. 
      (Get-TransportService) | Get-MessageTrackingLog
      throws errors
      Get-TransportService | Get-MessageTrackingLog
      throws errors
      (Get-TransportService).name | Get-MessageTrackingLog
      works - spits results for several seconds (perhaps 1000 lines per transport server, judging from the warnings)
    • Hi Nuno,
      
      
      Thank you for this tool but when i try to run it on my CAS Environment nothing happen.
      
      I have 2 CAs 2010 onWin2k8 2MBX on Win2k8
      
      I would apreciate a help on this.
    • Hi Gina,
      
      What do you mean nothing happens? There is no output at all? Any errors? Are you running the script from the EMS? Please make sure that $From is not a date in the future otherwise there won't be any data printed indeed (other than the first line with the headers).
      
      Regards, Nuno
  • Question on script
    2 Posts | Last post November 28, 2016
    • Hello Nuno, i first would like to thank you for your efforts for helping the community.
      
      I have a need to report back the email statistics for a particular exchange database, is there a way we achieve this or may be if i get a list of email address - number of email they have received, i will put the data in excel and run a comparison against users part of the particular database, need in hand to prove the utilization of an exchange database.
      
      Thanks
      -Inderjit Singh
      ijs@jda.com
    • Hello Inderjit,
      
      Thank you for your comment!
      I'm afraid the way the script is written, it doesn't facilitate reporting on a user or group of users...
      You can check the answers below where I mention how to run the script for a particular user. You could also add a parameter to the switch so that you could call the script automatically for multiple users, but that would require a significant change to the original script...
      
      Regards,
      Nuno
  • Output to a file
    2 Posts | Last post October 20, 2016
    • Nuno -
      
      How can I output the script to a file instead of writing to the screen?
    • Hi,
      
      You can simply update the line where I print $strEmails to something like this:
      $strEmails >> report.csv
      
      Regards,
      Nuno
  • Emails Sent and Received Per Day and Size by a user in exchange 2013 for last 30 days
    2 Posts | Last post October 16, 2016
    • Hi Nuno,
      
      Need urgent help. Please help me to create the report in below format in exchange 2013 for a single user.
      
      Daily Traffic Summary from 2016-09-01 to 2016-09-30
      				
      Selection of mailboxes:			
      				
      Rahul Mallaiya, rahul.mallaiya@abc.com
      	
      				
      Day	Sent Number	Sent Size, MB	Received Number	Received Size, MB
      Thursday, 2016-09-01	0	0	107	5,31
      Friday, 2016-09-02	0	0	100	6,23
      Saturday, 2016-09-03	0	0	32	0,84
      Sunday, 2016-09-04	0	0	56	0,66
      Monday, 2016-09-05	0	0	115	17,96
      Tuesday, 2016-09-06	0	0	103	5,48
      Wednesday, 2016-09-07	0	0	112	5,37
      Thursday, 2016-09-08	0	0	98	6,24
      Friday, 2016-09-09	0	0	148	16,52
      Saturday, 2016-09-10	0	0	30	1,01
      Sunday, 2016-09-11	0	0	89	2,72
      Monday, 2016-09-12	0	0	190	51,63
      Tuesday, 2016-09-13	0	0	149	43,54
      Total	0	0	1329	163,51
      				
      Date: 1 October 2016; Multiple sending counted1		
      
    • Hi Rahul,
      
      That is not too hard. All you have to do is split the search line:
      (Get-TransportServer) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach {
      
      into two separate searches. One for emails sent:
      (Get-TransportServer) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To -Sender rahul.mallaiya@abc.com -EventId RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach {
      	$intSent++
      	$intSentSize += $_.TotalBytes
      }
      
      And another one for received emails:
      (Get-TransportServer) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To -Recipients rahul.mallaiya@abc.com -EventId DELIVER | ForEach {
      	$intRec++
      	$intRecSize += $_.TotalBytes
      }
      
      The rest is just normal output.
      
      Regards,
      Nuno
  • Can anyone help me to know if output is in KB or MB
    2 Posts | Last post September 29, 2016
    • I mean i am able to run script successfully but sent size & receive size, is it in MB or KB
    • Hi Suvi,
      
      The size is in MB. If you look at the code, first we add the sizes of all the emails in bytes ($intRecSize += $_.TotalBytes) and before printing it we convert the total to MB ($intSentSize = [Math]::Round($intSentSize/1MB, 0)
      
      Regards,
      Nuno
  • Can anyone help me to know if output is in KB or MB
    1 Posts | Last post September 29, 2016
    • Can anyone help me to know if output is in KB or MB
  • Errors when running
    4 Posts | Last post June 23, 2016
    • Hi Nuno,
      
      I get the following errors when I run the script.
      
      Get-Date : Cannot bind parameter 'Date'. Cannot convert value "20/11/2011" to type "System.DateTime". Error: "String
      was not recognized as a valid DateTime."
      At D:\Scripts\TotalEmailsSentReceivedPerDay.ps1:2 char:18
      + $From = Get-Date "20/11/2011"
      +                  ~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
          + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
      
      You cannot call a method on a null-valued expression.
      At D:\Scripts\TotalEmailsSentReceivedPerDay.ps1:3 char:1
      + $To = $From.AddDays(1)
      + ~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      DayOfWeek,Date,Sent,Sent Size,Received,Received Size
      You cannot call a method on a null-valued expression.
      At D:\Scripts\TotalEmailsSentReceivedPerDay.ps1:14 char:40
      +     $strEmails = "$($From.DayOfWeek),$($From.ToShortDateString()),"
      +                                        ~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      Cannot process argument transformation on parameter 'Start'. Cannot convert null to type "System.DateTime".
          + CategoryInfo          : InvalidData: (:) [Get-MessageTrackingLog], ParameterBindin...mationException
          + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MessageTrackingLog
      
      Any ideas?
    • I figured out my issue. The Date format was incorrect on line 4. Is it possible to run the script with a From variable of the last 30 days? That way the script could run from a scheduled task without my having to modify the From date. Then add an export to csv option?
    • Hi jcollotzi,
      
      You need to update the date to the correct format depending if your servers have the date in US format or not, i.e., dd/mm/yyyy or mm/dd/yyyy.
      If you want start from 30 days ago, you can use something like this: (Get-Date).AddDays(-30)
      
      Regards,
      Nuno
    • Hi jcollotzi,
      
      You need to update the date to the correct format depending if your servers have the date in US format or not, i.e., dd/mm/yyyy or mm/dd/yyyy.
      If you want start from 30 days ago, you can use something like this: (Get-Date).AddDays(-30)
      
      Regards,
      Nuno
1 - 10 of 38 Items