Get-MessageTrackingLog Sender, get only a select list of senders not all.

I had this question after viewing Exchange Mgmt Shell get-messagetrackinglog: Need it to output more fields..

Looking to get specific senders, about 8 or so.  When I run the above, it returns everything and it's time consuming to filter through excel.
Wes HunterIT OperationsAsked:
Who is Participating?
 
Wes HunterIT OperationsAuthor Commented:
Looking to expand on somthing like this: (Just need to have a 8 or so email addresses returned with their counts, not all, havn't found out how to get this solution).  Also, really looking for a send count on these specific 8 senders.

Get-MessageTrackingLog -ResultSize Unlimited -start “2/8/2018 00:00:00” -end “3/8/2018 11:59:00” | select-object -ExpandProperty Recipients | group-object | export-csv c:\users\csadmin\desktop\user-receive-all.csv
0
 
CodeTwo SoftwareSoftware DeveloperCommented:
Please take a look at the article: Message tracking logs in Exchange Server. It explains how to use Get-MessageTrackingLog for different purposes, including an explanation on how to display the send count. If you want to limit results to the chosen senders, save them to a variable like $Senders (you can use Get-mailbox, Get-DistributionGroupMember, or import them from a CSV file) and then use this variable in the script:
Get-MessageTrackingLog -ResultSize Unlimited -start “2/8/2018 00:00:00” -end “3/8/2018 11:59:00” | Where-Object -Property Sender -Like ($Senders).Name | Group-Object -Property Sender | Select-Object name,count | Sort-Object count -Descending | export-csv c:\users\csadmin\desktop\user-receive-all.csv

Open in new window

0
 
Wes HunterIT OperationsAuthor Commented:
Thank you,.. I've tried this a few different ways, and it doesn't work.  I used the following.
Didn't work: $Senders = ("address1@mydomain.com", "address2@mydomain.com", "address3@mydomain.com")
Didn't work: .\addresses.txt was text file with address1@mydomian.com and the other addresses immediately below . No header.
I should say it partially worked, it turned up empty user column, but count only returned one count of 34 which I know is very low.
Get-Content .\addresses.txt |
ForEach {
        $msgCount = (Get-MessageTrackingLog -Server svrname-recipients $_ -Start "02/08/2018 00:00:00" -End "03/8/2018 00:00:00" |  Measure-Object).Count

        $propList = @{
                      "User"=$_
                      "Message Count"=$msgCount
                      }

                      New-Object PsCustomObject -Property $propList
    } |

        Export-Csv .\NumberOfEmailMessagesReceived.csv -NoTypeInformation
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
CodeTwo SoftwareSoftware DeveloperCommented:
Sorry, I misunderstood. To get results per sender, when you have a variable $Senders like in the example above ( $Senders = ("address1@mydomain.com", "address2@mydomain.com", "address3@mydomain.com") ), you can use the following loop:
ForEach ($Sender in $Senders)
{Get-MessageTrackingLog -ResultSize Unlimited -start (get-date).AddDays(-1) | Where-Object -Property Sender -Like $Sender | Group-Object -Property Sender | Select-Object name,count  >> c:\users\csadmin\desktop\user-receive-all.csv}

Open in new window

Mind that in the current form, the cmdlet returns send count from the last 24 hours.
0
 
Wes HunterIT OperationsAuthor Commented:
Thank you for the reply!! I ran it and received this:

Where-Object : A parameter cannot be found that matches parameter name 'Property'.
At line:1 char:132
+ ForEach ($Sender in $Senders) {Get-MessageTrackingLog -ResultSize Unlimited -start (get-date).AddDays(-30) | Where-Ob
ject -Property <<<<  Sender -Like $Sender | Group-Object -Property Sender | Select-Object name,count  >> c:\users\csadm
in\desktop\Sender_COUNTS.csv}
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand
0
 
CodeTwo SoftwareSoftware DeveloperCommented:
That is strange, you could delete the -Property parameter name from the script (after the Where-Object cmdlet), as it is optional anyway, but I am not sure if it will help - I could not replicate the same error in my environment.
0
 
Wes HunterIT OperationsAuthor Commented:
Removing -Property did not work, also removed -Property Sender, and that did not work either.
0
All Courses

From novice to tech pro — start learning today.