locked
Script for pulling last 30 days send items, inbox items inside a particular OU or accepted domain RRS feed

  • Question

  • Dear Friends,

    I got  requirement to pull the mail-flow (Send items count,Inbox items count, last login time)for the last 30 days for some mailboxes in Exchange 2013 (Mailboxes inside an OU and a specific accepted domain.

    I got a script from Justin Beeden, but can't drilldown to a specific OU or Accepted domain that i need. Also i ran for the entire organisation sparing a lot of time, all completed fine, but instead of pulling 3500 mailbox details, the output was only 1000. Please check the script below and let me know what i am missing.

    The script is not fully copied here.

    #Requires -version 2.0

    Param(
        [Parameter(Position=0, Mandatory = $true,
        HelpMessage="Enter the number of days to go back and search message tracking log files.")]
        [int]$DaysToGoBack,

        [Parameter(Mandatory = $false)]
        [switch]$IncludeDistListStats,

        [Parameter(Mandatory = $false)]
        [switch]$Include2013HealthMailboxes
    )
    $rundate = $(Get-Date).toshortdatestring()
    $startdate = $((Get-Date).adddays(-$DaysToGoBack)).toshortdatestring()

    $outfile_date = ([datetime]$rundate).tostring("yyyy_MM_dd") 
    $outfile = "$DaysToGoBack" + "DaysMessageStats_" + $outfile_date + ".csv"
     
    $dloutfile = "DistListStats_" + $outfile_date +".csv"
     
    $accepted_domains = Get-AcceptedDomain |Foreach {$_.domainname.domain} 
    [regex]$dom_rgx = "`(?i)(?:" + (($accepted_domains |% {"@" + [regex]::escape($_)}) -join "|") + ")$" 
     
    $mbx_servers = Get-ExchangeServer |Where {$_.serverrole -match "Mailbox"}|Foreach {$_.fqdn} 
    [regex]$mbx_rgx = "`(?i)(?:" + (($mbx_servers |Foreach {"@" + [regex]::escape($_)}) -join "|") + ")\>$" 
     
    $msgid_rgx = "^\<.+@.+\..+\>$" 
     
    $hts = Get-TransportServer -WarningAction SilentlyContinue | Foreach {$_.name} 
     
    $exch_addrs = @{} 
    $msgrec = @{} 
    $bytesrec = @{} 
    $msgrec_exch = @{} 
    $bytesrec_exch = @{} 
    $msgrec_smtpext = @{} 
    $bytesrec_smtpext = @{} 
    $total_msgsent = @{} 
    $total_bytessent = @{} 
    $unique_msgsent = @{} 
    $unique_bytessent = @{} 
    $total_msgsent_exch = @{} 
    $total_bytessent_exch = @{} 
    $unique_msgsent_exch = @{} 
    $unique_bytessent_exch = @{} 
    $total_msgsent_smtpext = @{} 
    $total_bytessent_smtpext = @{} 
    $unique_msgsent_smtpext=@{} 
    $unique_bytessent_smtpext = @{} 
    $dl = @{} 
     
    $obj_table = { 
    @" 
            Date = $rundate 
            User = $($address.split("@")[0]) 
            Domain = $($address.split("@")[1]) 
            Sent Total = $(0 + $total_msgsent[$address]) 
            Sent MB Total = $("{0:F2}" -f $($total_bytessent[$address]/1mb)) 
            Received Total = $(0 + $msgrec[$address]) 
            Received MB Total = $("{0:F2}" -f $($bytesrec[$address]/1mb)) 
            Sent Internal = $(0 + $total_msgsent_exch[$address]) 
            Sent Internal MB = $("{0:F2}" -f $($total_bytessent_exch[$address]/1mb)) 
            Sent External = $(0 + $total_msgsent_smtpext[$address]) 
            Sent External MB = $("{0:F2}" -f $($total_bytessent_smtpext[$address]/1mb)) 
            Received Internal = $(0 + $msgrec_exch[$address]) 
            Received Internal MB = $("{0:F2}" -f $($bytesrec_exch[$address]/1mb)) 
            Received External = $(0 + $msgrec_smtpext[$address]) 
            Received External MB = $("{0:F2}" -f $($bytesrec_smtpext[$address]/1mb)) 
            Sent Unique Total = $(0 + $unique_msgsent[$address]) 
            Sent Unique MB Total = $("{0:F2}" -f $($unique_bytessent[$address]/1mb)) 
            Sent Internal Unique  = $(0 + $unique_msgsent_exch[$address])  
            Sent Internal Unique MB = $("{0:F2}" -f $($unique_bytessent_exch[$address]/1mb)) 
            Sent External  Unique = $(0 + $unique_msgsent_smtpext[$address]) 
            Sent External Unique MB = $("{0:F2}" -f $($unique_bytessent_smtpext[$address]/1mb)) 
    "@ 

     


    • Edited by Arun Pillai_SP Thursday, February 8, 2018 8:46 AM
    • Moved by Bill_Stewart Monday, March 12, 2018 9:32 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, February 8, 2018 8:46 AM

All replies

  • > Also i ran for the entire organisation sparing a lot of time, all completed fine, but instead of pulling 3500 mailbox details, the output was only 1000.

    Is there a Get-Mailbox command somewhere in the not copied part of the script? I guess, at least one of the Exchange commands is missing the "-resultsize unlimited" switch.


    • Edited by TobyU Thursday, February 8, 2018 8:57 AM
    Thursday, February 8, 2018 8:51 AM
  • We cannot fix third party scripts for you.  Ask the author for help.

    Please carefully review the following links to set your expectation of technical forums.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests


    \_(ツ)_/

    Thursday, February 8, 2018 8:54 AM