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