Get-MessageTrackingLog expand all recipients

When you run Get-MessageTrackingLog to find emails send by someone or with some subject, then you will get list of recipients.

Recipients are returned as SystemObject to you can’t save them to file because you will get in file only string SystemObject[]

Also in Exchange Mamangement Shell you will get recipients list which ends with

So to display all recipients in EMS you need to modify Get-MessageTrackingLog using function join.

With join we will create string with all recipients separated by comma.

[string]::join(",",$_.recipients)

 

 

Now you need to add join to Get-MessageTrackingLog like this example, where you will get all emails sent by john@domain.com :

Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited-eventid receive | ? {$_.sender -like "john@domain.com"  -and $_.source -eq "STOREDRIVER"} | Select-Object timestamp, sender, messagesubject, @{label="recipients";expression={[string]::join(",",$_.recipients)}} | sort timestamp | ft -auto

 

As a result we will get timestamp, sender address, message subject, and recipients in one line separated by comma.

But if you will get many recipients then EMS will display only few and will end by …

To get all recipinets in one line and save them in to a file you can use operator > and Out-String like below:

Out-String -Width 4096 > D:\logs\emails_sent.txt

 

Now your command will look like below:

Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited-eventid receive | ? {$_.sender -like "john@domain.com"  -and $_.source -eq "STOREDRIVER"} | Select-Object timestamp, sender, messagesubject, @{label="recipients";expression={[string]::join(",",$_.recipients)}} | sort timestamp | ft -auto | Out-String -Width 4096 > D:\logs\emails_sent.txt

 

Microsoft Exchange get sent emails list – messagetrackinglog

emailRecently we wrote about how to find all the all recipients of the email:

Exchange MessageTrackingLogs get recipients list

 

 

Now we will present a powershell script that will help us generate statistics of sent emails.

 

However, we are not interested in the amount of all outgoing e-mails, their size, but we will focus on emails sent outside of our Exchange organization and get information about the addresses from which they were sent, with which the subject, how many of these emails and how many recipients receive those emails.

This script allows you to obtain information about the senders e-mail addresses that send many messages out.
This script is based on checking the Transport Logs located on Exchange servers with the Hub Transport roles.

After receiving the results of the script you can use the script in the previous post and find out to whom the message was sent, then you will get list of all recipients of this email.

 

Below we explain how this script work.:

First script part conatins:

  • powershell object definitions
  • paths to output files with emails statistic
  • settings to send email with alert to admin
  • $MAX_Recipients – number of recipients which define when to generate alert sent by email

 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Set-AdServerSettings -ViewEntireForest $True

Function New-Array {,$args}

$Report = New-Array
$Report_SMTP = New-Array
$Rep_sum = New-Array
$Rep_SMTP_sum = New-Array

$data = $($((get-date).adddays(-1)).ToString('yyyy.MM.dd'))

#paths to output files
$Out_Rep_file = "d:\Scripts\Logs\Stats\msg_stat_out_$data.csv"
$Out_Rep_sum_file = "d:\Scripts\Logs\Stats\msg_stat_out_sum_$data.csv"

#files with emails with smtp traffic
$Out_Rep_SMTP_file = "d:\Scripts\Logs\Stats\msg_stat_smtp_out_$data.csv"
$Out_Rep_SMTP_sum_file = "d:\Scripts\Logs\Stats\msg_stat_smtp_out_sum_$data.csv"
#file with report attached to email (emails recipients grater than $MAX_Recipients)
$Email_HTML_File = "d:\Scripts\Logs\Stats\Report_outgoing_emails_$data.htm"

#settings for email with report
$mail_from = "exchangereport@domain.com"
$mail_to = "admin@domain.com"
$mail_smtp_host = "smtpserver.domain.local"
$mail_subject = "Report outgoing emails $data"

#variable that defines the threshold for recipients to write to email report
$MAX_Recipients = 100

Continue reading

Get-MessageTrackingLog how to speed up

Searching message tracking logs with cmdlet Get-MessageTrackingLog can take long time when you need to search few Hub Transport Servers.

Below command will search all transport logs on all Exchange Hub Transport servers and find only messages with subject “Important *”:

Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -start (get-date).adddays(-2) -end (get-date) -eventid Deliver | ? {$_.messagesubject -like "Important *"}

 

You can speed up this search by using remoting Powershell using CMDlet Invoke-Command.

You need to modify command like below and add Invoke-Command:

Get-TransportServer | Invoke-Command {Get-MessageTrackingLog -resultsize unlimited -start (get-date).adddays(-2) -end (get-date) -eventid Deliver | ? {$_.messagesubject -like "Important *"}}

 

 

Exchange Message Tracking Logs export to Excell

 

Very often we have to find emails sent from one mailbox to another.
Informations about sent messages in our Microsoft Exchange Server environment we can find in Message Tracking Logs which are located on Hub Transport servers

 

Mostly to explore Message Tracking Log we use GUI tool Tracking Log Explorer from Exchange Management Console. We can also use powershell to track messages which is more helpful. We can create powershell script to track messages using CMDlet Get-MessageTrackingLog.

 

How to use Get-MessageTrackingLog we will write next time.

Now we want to describe how to find informations about delivered messages to specified mailbox and how to easly export those informations to Excell where we can sort and filter them.

 

To find informations about sent or received message we have to check all Message Tracking Logs on all Hub Transport Servers in our Exchange environment.

When we want to get informations about messages delivered to mailbox we need to use Get-MessageTrackingLog with -EventId Deliver options, then we will receive only informations about messages with status delivered.

 

This link describes Get-MessageTrackingLog CMDlet and how to use it.

Before you will start looking for message, you need to know what is your message tracking logs configuration for Hub Transports Servers. You have to check where and how long those logs are held.

 

Below you can find script which will search all Hub Transport Servers and message transport logs for delivered messages to specified mailbox. This mailbox is defined in variable Recipient.

Continue reading