Exchange 2007 Message Tracking

Mich nervt diese umständliche Eingabe an Informationen beim Message Tracking. Ich brauche eine Quick and Dirty Lösung, da zu 95% immer nach Sender, Empfänger und Betreff in einem Bestimmten Zeitraum gesucht wird. Die Angabe des Servers (Hub oder MBX) soll automatisch (immer) erfolgen.

Schnell mal eine Lösung mit Powershell gebastelt, somit leicht modifizierbar! (Suchen über mehrere Tage würde das Zeitfenster pro Tag auf die angegebenen Zeiten beschränken. Da muss ich mir noch was überlegen, wie der LogParser wirklich Date+Time erkennen kann.)

Hier gehts zum script….

#$erroractionpreference = "SilentlyContinue"
#####
##### Array-Pfade zu den Log-Files der Exchangeserver (MBX, HUB, Edge)
#####
# Achtung: Array!
$aPfad =
"'\\EX02\d$\Program Files\Microsoft\Exchange Server\TransportRoles\Logs\MessageTracking\MSGTR*.LOG'",
"'\\EX03\d$\Program Files\Microsoft\Exchange Server\TransportRoles\Logs\MessageTracking\MSGTR*.LOG'",
"'\\EX08\d$\Program Files\Microsoft\Exchange Server\TransportRoles\Logs\MessageTracking\MSGTR*.LOG'",
"'\\EX09\d$\Program Files\Microsoft\Exchange Server\TransportRoles\Logs\MessageTracking\MSGTR*.LOG'"
$cPfad = [string]::join(", ", $aPfad)
###########################################################################################
Function SearchLogs {
#
# Suche alle Logs, baue zuerst das Datumsformat zusammen
#
$Sender = $objTextBoxS.Text
$DateVon = $objDatePickerVon.Value.ToShortDateString().Substring(6,4) + "-" +
$objDatePickerVon.Value.ToShortDateString().Substring(3,2) + "-" +
$objDatePickerVon.Value.ToShortDateString().Substring(0,2)

$TimeVon = $objTimePickerVon.Value.ToLongTimeString()
$DateBis = $objDatePickerBis.Value.ToShortDateString().Substring(6,4) + "-" +
$objDatePickerBis.Value.ToShortDateString().Substring(3,2) + "-" +
$objDatePickerBis.Value.ToShortDateString().Substring(0,2)

$TimeBis = $objTimePickerBis.Value.ToLongTimeString()
$Sender = $objTextBoxS.Text
$Recipient = $objTextboxR.Text
$Subject = $objTextBoxMS.Text

$cHelp = ""
if($Sender.length -gt 0) {
     $cHelp = $cHelp + " and sender-address like '%%$Sender%%' "
}
if ($Recipient.Length -gt 0) {
     $cHelp = $cHelp + " and recipient-address like '%%$Recipient%%' "
}
if ($Subject.Length -gt 0) {
     $cHelp = $cHelp + " and message-subject like '%%$Subject%%' "
}
$Execute = [char]34 + "select filename,substr([#Fields: date-time],0,10) AS DATE,
substr([#Fields: date-time],11,12) As Time, client-ip, client-hostname, server-ip,
server-hostname,connector-id,source,event-id,message-id,recipient-address,recipient-status,
total-bytes, recipient-count, message-subject,sender-address, return-path
from $cPfad where (date >='$DateVon' and time >=$TimeVon) and (date <= '$DateBis' and time <='$TimeBis') $cHelp
order by date,time asc" + [char]34 + " -i:CSV -nSkipLines:4 -o:DATAGRID"

$objTextBoxResult.Text = $Execute
[Diagnostics.Process]::start("C:\Program Files (x86)\Log Parser 2.2\logparser.exe",$Execute)
}
###########################################################################################
###########################################################################################
# Message Tracking Log Parser über alle Exchange-Logs gleichzeitig #
# MAIN Application #
# (c) 2009 by M.Hans@dynasys.de #
# #
###########################################################################################
#
# Variable and Inputs
#
#
# etwas .Net benötigen wir dazu
#
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$WhatToDo = "CANCEL"
#
# Formular
#
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Message Tracking..."
$objForm.Size = New-Object System.Drawing.Size(480,330)
$objForm.FormBorderStyle = "FixedSingle"
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$WhatToDo="CANCEL"; $objForm.Close()}})
#
# Suche Button
#
$SearchButton = New-Object System.Windows.Forms.Button
$SearchButton.Location = New-Object System.Drawing.Size(22,250)
$SearchButton.Size = New-Object System.Drawing.Size(95,23)
$SearchButton.Text = "Suche..."
$SearchButton.Add_Click({SearchLogs ;})
$objForm.Controls.Add($SearchButton)
#
# Cancel Button
#
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(348, 250)
$CancelButton.Size = New-Object System.Drawing.Size(95,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$WhatToDo="CANCEL";$objForm.Close()})
$objForm.Controls.Add($CancelButton)
# ###############
# Label-"Sender"
# ###############
$objLabelS = New-Object System.Windows.Forms.Label
$objLabelS.Location = New-Object System.Drawing.Size(18, 18)
$objLabelS.Size = New-Object System.Drawing.Size(120,13)
$objLabelS.Text = "Sender (Mailadresse):"
$objForm.Controls.Add($objLabelS)
#
# TextBox-Sender
#
$objTextBoxS = New-Object System.Windows.Forms.TextBox
$objTextBoxS.Location = New-Object System.Drawing.Size(155, 15)
$objTextBoxS.Size = New-Object System.Drawing.Size(286, 20)
$objForm.Controls.Add($objTextBoxS)
# ###############
# Label-"Recipient"
# ###############
$objLabelR = New-Object System.Windows.Forms.Label
$objLabelR.Location = New-Object System.Drawing.Size(18, 40)
$objLabelR.Size = New-Object System.Drawing.Size(135,13)
$objLabelR.Text = "Empfänger (Mailadresse):"
$objForm.Controls.Add($objLabelR)
#
# TextBox-Recipient
#
$objTextBoxR = New-Object System.Windows.Forms.TextBox
$objTextBoxR.Location = New-Object System.Drawing.Size(155, 37)
$objTextBoxR.Size = New-Object System.Drawing.Size(286, 20)
$objForm.Controls.Add($objTextBoxR)
# ###############
# Label-"Subject"
# ###############
$objLabelMS = New-Object System.Windows.Forms.Label
$objLabelMS.Location = New-Object System.Drawing.Size(18, 65)
$objLabelMS.Size = New-Object System.Drawing.Size(135,13)
$objLabelMS.Text = "Subject:"
$objForm.Controls.Add($objLabelMS)
#
# TextBox-Subject
#
$objTextBoxMS = New-Object System.Windows.Forms.TextBox
$objTextBoxMS.Location = New-Object System.Drawing.Size(155, 62)
$objTextBoxMS.Size = New-Object System.Drawing.Size(286, 20)
$objForm.Controls.Add($objTextBoxMS)
# ###############
# Label-Datum Von
# ###############
$objLabelVon = New-Object System.Windows.Forms.Label
$objLabelVon.Location = New-Object System.Drawing.Size(18, 87)
$objLabelVon.Size = New-Object System.Drawing.Size(135,13)
$objLabelVon.Text = "Datum von:"
$objForm.Controls.Add($objLabelVon)
#
# Date Picker
#
$objDatePickerVon = New-Object System.Windows.Forms.DateTimePicker
$objDatePickerVon.Location = New-Object System.Drawing.Size(155, 84)
$objDatePickerVon.Size = New-Object System.Drawing.Size(186, 20)
$objForm.Controls.Add($objDatePickerVon)
#
# Time Picker
#
$objTimePickerVon = New-Object System.Windows.Forms.DateTimePicker
$objTimePickerVon.Format = 4 # Time
$objTimePickerVon.ShowUpDown = $TRUE
$objTimePickerVon.Location = New-Object System.Drawing.Size(341, 84)
$objTimePickerVon.Size = New-Object System.Drawing.Size(100, 20)
$objForm.Controls.Add($objTimePickerVon)
# ###############
# Label-Datum Bis
# ###############
$objLabelBis = New-Object System.Windows.Forms.Label
$objLabelBis.Location = New-Object System.Drawing.Size(18, 109)
$objLabelBis.Size = New-Object System.Drawing.Size(135,13)
$objLabelBis.Text = "Datum bis:"
$objForm.Controls.Add($objLabelBis)
#
# Date Picker
#
$objDatePickerBis = New-Object System.Windows.Forms.DateTimePicker
$objDatePickerBis.Location = New-Object System.Drawing.Size(155, 106)
$objDatePickerBis.Size = New-Object System.Drawing.Size(186, 20)
$objForm.Controls.Add($objDatePickerBis)
#
# Time Picker
#
$objTimePickerBis = New-Object System.Windows.Forms.DateTimePicker
$objTimePickerBis.Format = 4 # Time
$objTimePickerBis.ShowUpDown = $TRUE
$objTimePickerBis.Location = New-Object System.Drawing.Size(341, 106)
$objTimePickerBis.Size = New-Object System.Drawing.Size(100, 20)
$objForm.Controls.Add($objTimePickerBis)
#
# TextBox-Result Statement
#
$objTextBoxResult = New-Object System.Windows.Forms.TextBox
$objTextBoxResult.MultiLine = $TRUE
$objTextBoxResult.ReadOnly = $True
$objTextBoxResult.ScrollBars = 2
$objTextBoxResult.Location = New-Object System.Drawing.Size(20, 134)
$objTextBoxResult.Size = New-Object System.Drawing.Size(423, 100)
$objForm.Controls.Add($objTextBoxResult)
#
# Form vorbereiten
#
$objForm.Add_Shown({$objForm.Activate()})
#
# Main Dialog
#
[void] $objForm.ShowDialog()
#
# Ende
#