In todays blog I am going to show you how to filter Message Tracking Log output from the Get-MessageTrackingLog command. I had a customer from an organisation example.com who wanted to see all external recipients who received an email with the message subject "Staffing Update".
Without using some PowerShell filtering, you can view all tracking log related entries for this against all Transport Servers in your organisation by running:
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update"
Note: If your running Exchange 2007 or 2010 replace Get-TransportService with Get-TransportServer.
This command will return all messages relayed in the last 30 days by default which is the amount of time the message tracking logs hang around for by default.
However if we want to meet my customers requirement, we want the output to not contain any recipients for "*@example.com" so that we can focus on emails leaving the company. When I say external users or "leaving the company", I mean users who do not have an email address for "*@example.com", you may have an Exchange Organisation where you have multiple accepted domains setup for multi-tenancy!
To do this we need to do some filtering with PowerShell. This can be achieved using the where{ } command as follows:
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update" | where{$_.recipients -notlike "*@example.com"}
But say we only want to see which users received this message with a @example.com email address. Easy this can be done by reverting the -notlike to a -like.
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update" | where{$_.recipients -like "*@example.com"}
You can also easily filter senders by replacing the $_.recipients line with $_.senders like shown below:
where{$_.sender -like "*@example.com"}
Happy Filtering!
Without using some PowerShell filtering, you can view all tracking log related entries for this against all Transport Servers in your organisation by running:
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update"
Note: If your running Exchange 2007 or 2010 replace Get-TransportService with Get-TransportServer.
This command will return all messages relayed in the last 30 days by default which is the amount of time the message tracking logs hang around for by default.
However if we want to meet my customers requirement, we want the output to not contain any recipients for "*@example.com" so that we can focus on emails leaving the company. When I say external users or "leaving the company", I mean users who do not have an email address for "*@example.com", you may have an Exchange Organisation where you have multiple accepted domains setup for multi-tenancy!
To do this we need to do some filtering with PowerShell. This can be achieved using the where{ } command as follows:
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update" | where{$_.recipients -notlike "*@example.com"}
But say we only want to see which users received this message with a @example.com email address. Easy this can be done by reverting the -notlike to a -like.
Get-TransportService | Get-MessageTrackingLog -MessageSubject "Staffing Update" | where{$_.recipients -like "*@example.com"}
You can also easily filter senders by replacing the $_.recipients line with $_.senders like shown below:
where{$_.sender -like "*@example.com"}
Happy Filtering!
Hi, this is very helpful, is there a way to just get a count on the number of emails sent externally?
ReplyDelete