Customised Exchange tracking log reports

I am currently running an automated script to run the below command which extracts the exchange message sendt,received report from my CAS/HUB server on a daily basis

Get-MessageTrackingLog -ResultSize Unlimited | Group-Object -Property:EventId | Sort-Object Count -Desc | Select Name,Count

Our management wants a customised report where certain feilds are renamed from the default values ..as below ..is this achievable ...or its too much to ask for.

March 17th, 2015 5:40am

Hi Shiva,

Should not be much problem to get it customized, you would just need so extra formatting and output codes.

Please post the full script so the it can be modified as per your current usage.

Your current cmdlets output is just Name,Count nothing

Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 7:45am

here is the full script I am running

function Load_Exchange_Tools {
 if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange.Management.PowerShell.e2010'})) {
  Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
 }
}
Load_Exchange_Tools
Get-MessageTrackingLog -Sender "no-reply@xxx.com" -Start (Get-Date).AddHours(-24) -End (Get-Date).AddHours(0) -resultsize "unlimited" |Group-Object -Property:EventId | Sort-Object Count -Desc | Select Name,Count >d:\rep\xxx.txt

March 18th, 2015 12:33am

Hi Shiva,

Please find the script below.

ExTrackingLogsCustom.ps1

#Script to extract Exchange Tracking logs and format the output as per custom name.


function Load_Exchange_Tools {
  if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange.Management.PowerShell.e2010'})) {
   Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
  }
 }
 Load_Exchange_Tools 



$result = Get-MessageTrackingLog -Sender "no-reply@xxx.com" -Start (Get-Date).AddHours(-24) -End (Get-Date).AddHours(0) -resultsize "unlimited" |Group-Object -Property:EventId | Sort-Object Count -Desc | Select Name,Count


$a = "Name" +"`t"+ "Count" +"`r`n" #This is the header with tab seperator `t for the output
foreach ($i in $result) 
{ 

#Case for replacing the names or keeping the default if no match found
#You can add remove more as required.
switch ($i.Name)

{
     "RECEIVE" {$j="Generated"; break}
     "SEND" {$j="Sent Externally"; break}
     "DELIVER" {$j="Sent Internally- Staff"; break}
     "RESOLVE" {$j="Remove"; break}
     "TRANSFER" {$j="Remove"; break}
     "REDIRECT" {$j="Remove"; break}

     default {$j=$i.Name; break}
}


$a += $j +"`t" + $i.Count +  "`r`n"


}

#$a
out-file -filepath d:\rep\xxx.xls -inputobject $a

Free Windows Admin Tool Kit Click here and download it now
March 18th, 2015 7:43am

Many thanks

Just one more

we do not want the below fields  in the output

    "RESOLVE" {$j="Remove"; break}
    
"TRANSFER" {$j="Remove"; break}
    
"REDIRECT" {$j="Remove"; break}

-regards

Shiva


March 18th, 2015 8:58am

Hi Shiva,

Thought so :)

Use the below update; wrap an if{ } statement around the output variable $a.

if ($j -notlike "Remove") {
$a += $j +"`t" + $i.Count +  "`r`n"
}

NOTE:- Don't delete the earlier switch case's "Remove" statements

Free Windows Admin Tool Kit Click here and download it now
March 19th, 2015 5:30am

Thanks a ton,I eventually managed tweaking some values from the script you have provded and got it as required.

Wondering if  output  can be sent directly as a well formatted HTML format ..to the mail recipient ..I have scheduled to run the report and then mail to recipients ..but it goes out as a text attachment in generic format ..Can I format into a more presenable format directly as mail body ?

Thanks in advance ..

March 19th, 2015 6:27am

Hi Shiva,

Yes that is quite possible, but would require you to have a bit of html knowledge and lots of patience to get the output right.

Below is a link that does it very well.

https://gallery.technet.microsoft.com/office/Exchnage-2010-Database-f6961eb8

Run the schduled task on a Exchange server itself to email it directly.

Exchange 2010 and 2013 Database HTML report via Email:

https://gallery.technet.microsoft.com/office/d9af4a66-a908-4a3f-af10-380aa63c3a74

Free Windows Admin Tool Kit Click here and download it now
March 19th, 2015 6:39am

Thanks for your patience ..Cheers ..

MArking your solution as answer

Good Day! Mate ..you are very helpful.

March 19th, 2015 6:45am

Thank you Shiva.
Free Windows Admin Tool Kit Click here and download it now
March 19th, 2015 6:47am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics

Fields

Renamed to

Count

RECEIVE

Generated

48019

SEND

Send Externally

47005

DELIVER

Send Internally- Staff

868

FAIL

FAIL

146

RESOLVE

Remove

3

TRANSFER

Remove

2

REDIRECT

Remove

2