Log et al – Peter Curd

An irreverent peek into the inner rumblings of Peter Curd



Powershell to run Get-MessageTrackingLog on multiple machines

By pcurd

I have an infrastructure with multiple Exchange 2007 servers and wanted to compile a list of all emails sent by two email addresses. Whilst Get-MessageTrackingLog did what I wanted, it only ran on one server at a time and would only search for one email address.

To get around this I wrote a PowerShell script to run Get-MessageTrackingLog for each sending email address and each computer. This is then combined into one CSV file for transfer to Excel.

$computers = "server1", "server2"
$senders = "Email1@domain.com", "Email2@domain.com"
$outputfile = "C:\output.csv"

$start = "DD/MM/YYYY HH:MM:SS"
$end = "DD/MM/YYYY HH:MM:SS"

$(foreach ($sender in $senders) {
$(foreach ($computer in $computers) {
get-messagetrackinglog -Sender $sender -Start $start -End $end -EventID "RECEIVE" -Server $computer | select Timestamp, @{Name="Recipients";expression={$_.Recipients}}, MessageSubject, Sender

})}) | sort-object -property timestamp | Export-CSV -path $outputfile -notype

4 Responses so far

Hi PCurd,
How do I execute the PowerShell script you have written assuming I have entered all correct mail servers, date/time & senders’ address?

Exchange Guy

Thanks for commenting! I would save the contents of the script to a new file and give it a .ps1 extension (to mark it as a PowerShell script) then run from inside Powershell like:


Make sure to run from an Exchange Management Shell as the script requires the Exchange components. To automate or otherwise run from a normal Powershell window add:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

To the top of the script so that the Exchange component is loaded.

Hi PCurd,
First of all I would to thank you for sharing this powershell script. It worked nicely & I was able to create a report I need. This is really much appreceiated.

If you don’t mind I have favor to ask, I would like to have a script this time for inbound emails that i can enter multiple internal recipients (company employees) I want received from any senders wether from internal and/or external users. In short, the script is the reverse of the first script you have shared.

Thanks in advance.
Exchange Guy

Please disregard my previous comment. I think i got it, I have created a script & looks like it is working. Thanks.

Exchange Guy

Leave a comment