Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I search my Exchange logs using Powershell?
    primarykey
    data
    text
    <p>This is a preliminary script, it's a bit ugly and needs some work (esp. the pop3 logs section) but I use it periodically to make my life easier. It's intended to be used in the Powershell ISE so I included the Easy Rerun section at the bottom. Feel free to offer suggestions, fixes, and cleanup if you find it useful.</p> <p>Make sure to update the MailServerName and Log Folders to match your environment.</p> <blockquote><pre> # == Begin by setting these == $SearchFilter = "sonic.net" $StartDate = (Get-Date).AddDays(-1) #(Get-Date 10/01/2012) $EndDate = (Get-Date).AddDays(-0) #(Get-Date 11/01/2012) $mailserver = "MailServerName" $OutputFolder = "$env:userprofile\Desktop\ExchangeLogs\" $IISLogsFolder = "\\$mailserver\c$\inetpub\logs\LogFiles\W3SVC1" $POP3LogsFolder = "\\$mailserver\c$\Program Files\Microsoft\Exchange Server\V14\Logging\POP3" # Untested $SMTPLogsFolder = "\\$mailserver\c$\Program Files\Microsoft\Exchange Server\V14\TransportRoles\Logs\MessageTracking" $POP3OutFile = "$OutputFolder\ExchangePOP3Logs.csv" $IISOutFile = "$OutputFolder\ExchangeIISLogs (owa, exchange, and activesync).csv" $SMTPOutFile = "$OutputFolder\ExchangeSMTPLogs.csv" # == Initialization == function Check-IISLogs { $IISFiles = Get-ChildItem $IISLogsFolder *.log|Where-Object {($_.CreationTime -gt $StartDate) -and ($_.CreationTime -lt $EndDate)} $IISHeader = ($IISFiles|Select-Object -First 1|Get-Content|select-string "#fields"|Select-Object -First 1).ToString().Substring(9).split(" ") $IISLogs = $IISFiles|Get-Content|Select-String $SearchFilter # might be able to do RegEx search (untested) $IISLogsCsv = $IISLogs|ConvertFrom-Csv -Delimiter " " -header $IISHeader $IISLogsCSV|Export-Csv -Path "$IISOutFile" #start excel "$IISOutFile" } function Check-Pop3Logs { # !!!UNTESTED!!! $POP3Files = Get-ChildItem $POP3LogsFolder *.log|Where-Object {($_.CreationTime -gt $StartDate) -and ($_.CreationTime -lt $EndDate)} $POP3Header = ($POP3Files|Select-Object -First 1|Get-Content|select-string "#fields"|Select-Object -First 1).ToString().Substring(9).split(" ") #ToDo: update select-string, substring, and split([delimiter]) $POP3Logs = $POP3Files|Get-Content|Select-String $SearchFilter # might be able to do RegEx search (untested) $POP3LogsCsv = $POP3Logs|ConvertFrom-Csv -Delimiter " " -header $POP3Header #ToDo: update Delimiter $POP3LogsCSV|Export-Csv -Path "$POP3OutFile" #start excel "$POP3OutFile" } function Check-SMTPLogs { $SMTPFiles = Get-ChildItem $SMTPLogsFolder *.log|Where-Object {($_.CreationTime -gt $StartDate) -and ($_.CreationTime -lt $EndDate)} $SMTPHeader = ($SMTPFiles|Select-Object -First 1|Get-Content|select-string "#fields"|Select-Object -First 1).ToString().Substring(9).split(",") $SMTPLogs = $SMTPFiles|Get-Content|Select-String $SearchFilter # might be able to do RegEx search (untested $SMTPLogsCsv = $SMTPLogs|ConvertFrom-Csv -Delimiter "," -header $SMTPHeader $SMTPLogsCSV|Export-Csv -Path "$SMTPOutFile" #start excel "$SMTPOutFile" } # == Run == Check-IISLogs #Check-Pop3Logs # doesn't work yet Check-SMTPLogs New-Item -Type Directory $OutputFolder -ErrorAction silentlycontinue start $OutputFolder &lt;# -- Easy rerun $SearchFilter = "username" #$StartDate = (Get-Date).AddDays(-1) #(Get-Date 10/01/2012) #$EndDate = (Get-Date).AddDays(-0) #(Get-Date 11/01/2012) Check-IISLogs #Check-Pop3Logs # doesn't work yet Check-SMTPLogs start $OutputFolder #> </pre></blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload