<# .SYNOPSIS Wertet IIS-Logzeilen (W3C-Format) fuer MAPI/HTTP-Requests aus. .DESCRIPTION Nimmt IIS-Logzeilen per Pipeline entgegen (z.B. via Get-Content), filtert auf "/mapi" und zaehlt pro MailboxGUID und Stunde die Requests mit Status 200, 401 und sonstige. Die Spaltenpositionen werden aus der "#Fields:"-Headerzeile des IIS-Logs ermittelt. Fehlt diese (z.B. weil nur ein Ausschnitt gepipet wird), wird das IIS-Standardlayout angenommen. .EXAMPLE Get-Content C:\inetpub\logs\LogFiles\W3SVC1\u_ex251124.log | .\Get-MapiLogStats.ps1 .EXAMPLE Get-ChildItem C:\inetpub\logs\LogFiles\W3SVC1\u_ex2511*.log ` | Get-Content ` | .\Parse-IISMapilogs.ps1 ` | Export-Csv .\MapiStats.csv -NoTypeInformation .EXAMPLE Get-Content .\u_ex251124.log | .\Get-MapiLogStats.ps1 | Format-Table -AutoSize #> [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipeline)] [AllowEmptyString()] [string]$Line ) begin { Write-Host "Parsing IIS MAPI logs START" # IIS-Standardlayout als Fallback, falls keine #Fields-Zeile mitkommt $fieldIndex = @{ 'date' = 0 'time' = 1 'cs-uri-stem' = 4 'cs-uri-query' = 5 'sc-status' = 11 } $stats = @{} $lineCount = 0 $matchCount = 0 } process { $lineCount++ if ($lineCount % 10000 -eq 0) { Write-Host "Processed $lineCount lines..." } if ([string]::IsNullOrWhiteSpace($Line)) { return } # Headerzeilen auswerten bzw. ueberspringen if ($Line[0] -eq '#') { Write-Host "Processing new header line" if ($Line.StartsWith('#Fields:')) { $names = $Line.Substring(8).Trim() -split '\s+' $fieldIndex = @{} for ($i = 0; $i -lt $names.Count; $i++) { $fieldIndex[$names[$i]] = $i } } return } # Schneller Vorfilter, bevor die Zeile zerlegt wird if ($Line.IndexOf('/mapi', [System.StringComparison]::OrdinalIgnoreCase) -lt 0) { return } $parts = $Line.Split(' ') # Sicherstellen, dass /mapi wirklich im URI-Stem steht $uriStem = $parts[$fieldIndex['cs-uri-stem']] if ($uriStem -notmatch '(?i)^/mapi') { return } $matchCount++ $date = $parts[$fieldIndex['date']] $hour = $parts[$fieldIndex['time']].Substring(0, 2) $status = $parts[$fieldIndex['sc-status']] $query = $parts[$fieldIndex['cs-uri-query']] # MailboxGUID aus dem Query-String, z.B. MailboxId=1234...-...@contoso.com $mailbox = if ($query -match '(?i)MailboxId=([0-9a-f-]{36})') { $Matches[1].ToLowerInvariant() } else { '(ohne MailboxId)' } $key = '{0}|{1}|{2}' -f $mailbox, $date, $hour if (-not $stats.ContainsKey($key)) { $stats[$key] = [pscustomobject]@{ MailboxGuid = $mailbox Date = $date Hour = $hour Status200 = 0 Status401 = 0 Other = 0 Total = 0 } } $entry = $stats[$key] switch ($status) { '200' { $entry.Status200++ } '401' { $entry.Status401++ } default { $entry.Other++ } } $entry.Total++ } end { Write-Verbose ('{0} Zeilen gelesen, davon {1} MAPI-Requests.' -f $lineCount, $matchCount) $stats.Values | Sort-Object MailboxGuid, Date, Hour Write-Host "Parsing IIS MAPI logs END" }