none
Required send and recieve messages count and size in Exchange 2013 for single user

    Question

  • Hi all,

    how to get the HTML report for single user on weekly basis for send and receive message count and size .

    Thanks

    AM

    Monday, October 3, 2016 10:13 AM

Answers

  • [PS] D:\temp>Get-TransportService | Get-MessageTrackingLog -ResultSize Unlimited -Start "5/01/2016" -End "10/02/2016" -Sender "email" -EventID RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach { $intSent+
    + }

    Hi,

    Make sure message tracking log is enabled, you can run this command to check. By default, the max age of message tracking log is 90 days.

    Get-TransportService | FL *messagetracking*

    https://technet.microsoft.com/en-us/library/aa997984(v=exchg.150).aspx

    And for your requirement, I recommend this script:

    https://gallery.technet.microsoft.com/office/f2af711e-defd-476d-896e-8053aa964bc5

    I edit this script to meet your requirement, remember to edit "User@domain.com" to that single user.

    # Initialize some variables used for counting and for output  
    $From = Get-Date "09/27/2016"
    $To = $From.AddDays(7)  
      
    [Int64] $intSent = $intRec = 0 
    [Int64] $intSentSize = $intRecSize = 0 
    [String] $strEmails = $null  
      
    Write-Host "DayOfWeek,Date,Sent,Sent Size,Received,Received Size" -ForegroundColor Yellow  
      
    Do  
    {  
        # Start building the variable that will hold the information for the day  
        $strEmails = "$($From.DayOfWeek),$($From.ToShortDateString()),"  
      
        $intSent = $intRec = 0  
        (Get-TransportService) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach {  
            # Sent E-mails  
            If ($_.Sender -eq "User@domain.com" -and $_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") 
            { 
                $intSent++ 
                $intSentSize += $_.TotalBytes 
            } 
              
            # Received E-mails  
            If ($_.EventId -eq "DELIVER" -and $_.Recipients -like "User@domain.com") 
            { 
                $intRec++ 
                $intRecSize += $_.TotalBytes 
            } 
        }  
      
        $intSentSize = [Math]::Round($intSentSize/1MB, 0) 
        $intRecSize = [Math]::Round($intRecSize/1MB, 0) 
      
        # Add the numbers to the $strEmails variable and print the result for the day  
        $strEmails += "$intSent,$intSentSize,$intRec,$intRecSize"  
        $strEmails  
      
        # Increment the From and To by one day  
        $From = $From.AddDays(1)  
        $To = $From.AddDays(1)  
    }  
    While ($To -lt (Get-Date))  
    #While ($To -lt (Get-Date "09/27/2016"))


    Regards,

    Lynn-Li

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Edited by Lynn-LiModerator Tuesday, October 4, 2016 7:09 AM Edit script
    • Marked as answer by Am230089 Wednesday, October 5, 2016 8:28 AM
    Tuesday, October 4, 2016 4:57 AM
    Moderator

All replies

  • [Int] $intSent = $intRec = 0

    Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “10/01/2012” -End “11/01/2012” -Sender "user@domain.com" -EventID RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach { $intSent++ }

    Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “10/01/2012” -End “11/01/2012” -Recipients "user@domain.com" -EventID DELIVER | ForEach { $intRec++ }

    Write-Host "E-mails sent:    ", $intSent

    Write-Host "E-mails received:", $intRec

    You can try this and last two lines you can put into a html file


    Mihir Nayak If a post is helpful, please take a second to hit the green arrow on the left, or mark as answer, thanks

    Monday, October 3, 2016 10:23 AM
  • I am using exchange2013 sp1 CU13 and this command is not working in latest latest version.
    Monday, October 3, 2016 11:45 AM
  • i have updated the command from   Get-TransportServer to Get-transportservice but still page is blank.
    Monday, October 3, 2016 11:53 AM
  • i have updated the command from   Get-TransportServer to Get-transportservice but still page is blank.
    Please post the exact syntax of the command you are running.  Did you change the dates to something that would return something in your environment?

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread

    Monday, October 3, 2016 1:12 PM
  • [PS] D:\temp>Get-TransportService | Get-MessageTrackingLog -ResultSize Unlimited -Start "5/01/2016" -End "10/02/2016" -Sender "email" -EventID RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach { $intSent+
    + }
    Monday, October 3, 2016 1:31 PM
  • [PS] D:\temp>Get-TransportService | Get-MessageTrackingLog -ResultSize Unlimited -Start "5/01/2016" -End "10/02/2016" -Sender "email" -EventID RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach { $intSent+
    + }

    Hi,

    Make sure message tracking log is enabled, you can run this command to check. By default, the max age of message tracking log is 90 days.

    Get-TransportService | FL *messagetracking*

    https://technet.microsoft.com/en-us/library/aa997984(v=exchg.150).aspx

    And for your requirement, I recommend this script:

    https://gallery.technet.microsoft.com/office/f2af711e-defd-476d-896e-8053aa964bc5

    I edit this script to meet your requirement, remember to edit "User@domain.com" to that single user.

    # Initialize some variables used for counting and for output  
    $From = Get-Date "09/27/2016"
    $To = $From.AddDays(7)  
      
    [Int64] $intSent = $intRec = 0 
    [Int64] $intSentSize = $intRecSize = 0 
    [String] $strEmails = $null  
      
    Write-Host "DayOfWeek,Date,Sent,Sent Size,Received,Received Size" -ForegroundColor Yellow  
      
    Do  
    {  
        # Start building the variable that will hold the information for the day  
        $strEmails = "$($From.DayOfWeek),$($From.ToShortDateString()),"  
      
        $intSent = $intRec = 0  
        (Get-TransportService) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach {  
            # Sent E-mails  
            If ($_.Sender -eq "User@domain.com" -and $_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") 
            { 
                $intSent++ 
                $intSentSize += $_.TotalBytes 
            } 
              
            # Received E-mails  
            If ($_.EventId -eq "DELIVER" -and $_.Recipients -like "User@domain.com") 
            { 
                $intRec++ 
                $intRecSize += $_.TotalBytes 
            } 
        }  
      
        $intSentSize = [Math]::Round($intSentSize/1MB, 0) 
        $intRecSize = [Math]::Round($intRecSize/1MB, 0) 
      
        # Add the numbers to the $strEmails variable and print the result for the day  
        $strEmails += "$intSent,$intSentSize,$intRec,$intRecSize"  
        $strEmails  
      
        # Increment the From and To by one day  
        $From = $From.AddDays(1)  
        $To = $From.AddDays(1)  
    }  
    While ($To -lt (Get-Date))  
    #While ($To -lt (Get-Date "09/27/2016"))


    Regards,

    Lynn-Li

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Edited by Lynn-LiModerator Tuesday, October 4, 2016 7:09 AM Edit script
    • Marked as answer by Am230089 Wednesday, October 5, 2016 8:28 AM
    Tuesday, October 4, 2016 4:57 AM
    Moderator
  • thanks for your message.

    When i ran this command i am getting below error messages.


    At D:\Softwares\temp\AT.ps1:19 char:69
    +         If ($_.Sender -eq "am230089@abc.com" $_.EventId - ...
    +                                                                     ~~
    Unexpected token '$_' in expression or statement.
    At D:\Softwares\temp\AT.ps1:19 char:69
    +         If ($_.Sender -eq "am230089@abc.com" $_.EventId - ...
    +                                                                     ~~
    Missing closing ')' after expression in 'If' statement.
    At D:\Softwares\temp\AT.ps1:17 char:106
    + ...  $To | ForEach {
    +                    ~
    Missing closing '}' in statement block.
    At D:\Softwares\temp\AT.ps1:12 char:1
    + {
    + ~
    Missing closing '}' in statement block.
    At D:\Softwares\temp\AT.ps1:19 char:126
    + ... q "STOREDRIVER")
    +                    ~
    Missing while or until keyword in do loop.
    At D:\Softwares\temp\AT.ps1:19 char:126
    + ... q "STOREDRIVER")
    +                    ~
    Unexpected token ')' in expression or statement.
    At D:\Softwares\temp\AT.ps1:31 char:5
    +     }
    +     ~
    Unexpected token '}' in expression or statement.
    At D:\Softwares\temp\AT.ps1:43 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
    At D:\Softwares\temp\AT.ps1:44 char:27
    + While ($To -lt (Get-Date))
    +                           ~
    Missing statement body in while loop.
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : UnexpectedToken

    Tuesday, October 4, 2016 6:38 AM
  • Hi,

    I forget to add '-and' condition operator, sorry. I edited my reply. Please try again, thanks for understanding.


    Regards,

    Lynn-Li

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 4, 2016 7:08 AM
    Moderator
  • script is running in every server and very slow. still it is running in my 6th server.


    • Edited by Am230089 Tuesday, October 4, 2016 10:15 AM ch
    Tuesday, October 4, 2016 10:15 AM
  • Sorry to say that this is long time taking script.

    for every single day the script is is going to check the server .

    For single day it took 3 hours to fetch the data. if i go for 7 days it will take full days to check the mails.

    :(

    Tuesday, October 4, 2016 11:32 AM
  • How to print into the html
    Wednesday, October 5, 2016 8:29 AM