<# .SYNOPSIS Auflistung aller SMTP-Verbindungen zum Exchange Server .DESCRIPTION PowerShell Skript zur automatischen Auswertung der SmtpReceive-Log-Dateien auf einem oder mehreren Exchange Servern .EXAMPLE C:\Scripts\Exchange_SMTP_Connections.ps1 .NOTES Date: 08.01.2019 Author: Jan Kappen Website: https://www.zueschen.eu Twitter: @JanKappen Thanks to Mike F Robbins for his cool function, for more informations have a look at his blog: mikefrobbins.com #> #Requires -Version 3.0 function Get-SMTPConnections { [CmdletBinding()] param ( [Parameter(Mandatory, ValueFromPipeline)] [ValidateScript({ Test-Path -Path $_ -PathType Leaf -Include '*.log' })] [string[]]$LogFile ) PROCESS { foreach ($file in $LogFile) { $Headers = (Get-Content -Path $file -TotalCount 5 | Where-Object {$_ -like '#Fields*'}) -replace '#Fields: ' -split ',' Import-Csv -Header $Headers -Path $file | Where-Object {$_.'connector-id' -match 'NAME_RELAY_CONNECTOR'} | Select-Object -Unique -Property remote-endpoint } } } # $stringBuilder = New-Object System.Text.StringBuilder $list1 = New-Object System.Collections.Generic.List[System.String] $list2 = New-Object System.Collections.Generic.List[System.String] ## Definition der Log-Pfade ## Muss auf einem Exchange Server direkt noch angepasst werden # $cas1 = Get-ChildItem -Path 'C:\Temp\Exchange SMTP Receive Log\cas1\*.log' | Get-SMTPConnections | Sort-Object -Property remote-endpoint -Unique $cas2 = Get-ChildItem -Path 'C:\Temp\Exchange SMTP Receive Log\cas2\*.log' | Get-SMTPConnections | Sort-Object -Property remote-endpoint -Unique # Server 1 foreach ($cas in $cas1."remote-endpoint") { $cas = $cas -split(":") $cas = $cas[0] $null = $stringBuilder.Append("$cas`r`n") $list1.Add("$cas") } $list1 | Sort-Object -Unique # Server 2 foreach ($cas in $cas2."remote-endpoint") { $cas = $cas -split(":") $cas = $cas[0] $null = $stringBuilder.Append("$cas`r`n") $list2.Add("$cas") } $list2 | Sort-Object -Unique