locked
Exchange 2010/13 Script Help - Message Stats RRS feed

  • Question

  • I have attempted to repurpose this script:  https://gallery.technet.microsoft.com/office/f2af711e-defd-476d-896e-8053aa964bc5

    In the comments, the OP advises that the "Get-MessageTracking" statement can be split to separate the data gather for the sent and receive items.  I used this method in my script.  

    I need to gather the stats for a list of mailboxes in a CSV file for the last 30 days of traffic.  I set up an Import-CSV with a "ForEach" loop which then read the "Do...While" statement, gathers the stats, then spits them out to either "Write-Host" or CSV file.  After processing the "Get-MessageTracking" for the first user in the CSV file and going through the "Do...while" loop, the data that is output is correct, but when the loop runs again for the second user in the file, the "Get-MessageTracking" is not performed and the stats simply spit out a zero for send/receive for the remaining users in the list.  

    Can anyone advise why the "Do...While" statement is not processed for each user in the input file?  Thanks for your time.



    • Edited by r1ckJames Wednesday, January 2, 2019 3:33 PM
    Wednesday, January 2, 2019 3:31 PM

All replies

  • Hi r1ckJames,

    Here is the script that could achieve your requirement:

    Write-Host "Name,DayOfWeek,Date,Sent,Sent Size (MB),Received,Received Size (MB)" -ForegroundColor Yellow  
    $Mailboxes = import-csv c:/temp/mailbox.csv
    
    foreach ($Mailbox in $Mailboxes){
        $From = Get-Date "12/20/2018"
        $To = $From.AddDays(1)
        [Int64] $intSent = $intRec = 0
        [Int64] $intSentSize = $intRecSize = 0
        [String] $strEmails = $null
        Do
        {
            # Start building the variable that will hold the information for the day
            $strEmails = $Mailbox.Name+",$($From.DayOfWeek),$($From.ToShortDateString()),"
    
            $intSent = $intRec = 0
            (Get-TransportService) | Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach {  
            # Sent E-mails  
            If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER" -and $_.Sender -eq $Mailbox.Name) { 
                $intSent++ 
                $intSentSize += $_.TotalBytes 
            } 
              
            # Received E-mails  
            If ($_.EventId -eq "DELIVER" -and $_.Recipients -eq $Mailbox.Name) { 
                $intRec += $_.RecipientCount 
                $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))  
    Write-Host "`n---------------------------------------`n"
    
    }

    The .CSV file that I used to import mailboxes:

    The result of this script:

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, January 3, 2019 4:05 AM
  • Hi r1ckJames,

    Any update now?

    If the above suggestion helps, please be free to mark it as an answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, January 11, 2019 1:47 AM
  • Hi r1ckJames,

    Haven't received your update for a long time, any update now?

    If the above suggestion helps, please be free to mark it as answer for helping more people.

    Regards,

    Kyle Xu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, January 25, 2019 2:19 AM