Exporting the Exchange 2007 Message Tracking Log to CSV using Powershell.
Tuesday, January 13, 2009 8:38The message tracking log in Exchange 2007 gives you some nice statistical information on your mailflow.
Today, I’m interested in received messages between two dates. Furthermore, I want to know to which email address these messages were sent to. (If you query the message tracking log by recipient, and give an email address as the filter, Exchange will lookup the mailbox for that emaill address, and use that mailbox/recipient for filtering in stead of the email address given.)
So I started with this powershell command;
[PS] C:\>get-messagetrackinglog -Recipients:name@domain.com -EventID “RECEIVE”
-Start “1-1-2009 0:00:00″ -End “14-1-2009 0:00:00″
Wow.. that works. Now I want those results in Excel, so I export it to a CSV file by adding;
| Export-Csv C:\Export.csv
to the end of the line.
That almost did the trick. Problem is that I can no longer see the Recipients in the export! Since the Recipients property of the Microsoft.Exchange.Management.TransportLogSearchTasks.MessageTrackingEvent is an array of strings (System.String[]) it will show as “System.String[]” in the export. That’s not what I want!
So I need to “implode” the string array to a string. Furthermore, I don’t need ALL the information in the log. So I i will get only the stuff that’s interesting for me (like recipients, subject, sender, etc.)
This is what I ended up with;
[PS] C:\>get-messagetrackinglog -Recipients:name@domain.com -EventID “RECEIVE”
-Start “1-1-2009 0:00:00″ -End “14-1-2009 0:00:00″ | select-object MessageSubjec
t,Sender,ReturnPath,@{Name=”Recipients”;Expression={$_.recipients}}| Export-Csv
C:\Export.csv
And that finally worked as expected.
Leave a Reply
You must be logged in to post a comment.
