none
Message Count by Accepted Domain RRS feed

  • Question

  • Hi,

    I recently have been asked to run a report on Exchange message count for all internal messages, ie, all sent emails from our exchange platform to our accepted domains.
    This would be fairly simple if we had one or a few accepted domains and we could script it like -

    get-messagetrackinglog -ResultSize unlimited -Start “dd/mm/yyyy 00:00:00″ -End “dd/mm/yyyy 23:59:00″ | where {$_.Sender -like “*@domain.com“}  | where {$_.Recipients -like “*@domain.com“}

    But we have hundreds of accepted domains and we would like to see a count of which are sending between accpeted domains against the total internal and external emails.

    Is there any good way to get-AcceptedDomain and pipe it into a query to a count mail for Recipients -like "*AcceptedDomain"

    I have come to see this isn't as a simple task as I first thought.

    Thanks for any help.

    • Moved by Bill_Stewart Friday, March 15, 2019 6:37 PM This is not "scripts on demand"
    Friday, January 25, 2019 5:08 PM

All replies

  • You need to ask this question in the Exchange forum.  

    I am not sure what the best method for doing this might be but the Exchange guys can tell you the best way to do this.

    Here is one way to get all domains in your organization:

    $domains = Get-AcceptedDomain

    https://docs.microsoft.com/en-us/powershell/module/exchange/mail-flow/Get-AcceptedDomain?view=exchange-ps

    $acceptedDomains = Get-AcceptedDomain | Select -ExpandProperty DomainName
    Get-MessageTrackingLog -Start 'dd/mm/yyyy 00:00:00' -End 'dd/mm/yyyy 23:59:00' -ResultSize unlimited |
        Where-Object {
            ($_.Sender -replace '(.*)@(.*)', '$2') -in $acceptedDomains -and 
            ($_.Recipients -replace '(.*)@(.*)', '$2') -in $acceptedDomains 
        }

    You will have to resolve the issue with "Recipients" because it can have multiple values.  These will have to be enumerated like this.

    $_.Recipients | ForEach-Object{ $_  -replace '(.*)@(.*)', '$2')  -in $acceptedDomains }

    How you want to deal with this is unclear.


    \_(ツ)_/


    • Edited by jrv Friday, January 25, 2019 5:59 PM
    Friday, January 25, 2019 5:55 PM
  • Thanks for this, it's a big help.

    I shall move the thread into the Exchange forums and see if they have anything to add.

    Monday, January 28, 2019 12:35 PM