# Get-NDRData # # Load messagetrackinglogs and parse NDR-Data, to allow further processing # Especially for not delivered important messages due invalid sender configurations # noes not work, if invalid recipients are blocked at SMTP-level [cmdletbinding()] param ( $servername = "*", $startdate = (get-date).addminutes(-$durationMin), $durationMin = 5 ) Write-Verbose "Get-NDRData:Start" Write-Verbose " Param Servername : $($servername)" Write-Verbose " Param StartDate : $($startdate)" Write-Verbose " Param Duration : $($durationMin)" Write-Verbose " Param EndDate : $($enddate)" $enddate = (get-date $startdate).addminutes($durationMin) $startdate = (get-date $startdate) Write-Verbose " Calc StartDate : $($startdate)" Write-Verbose " Calc EndDate : $($enddate)" $serverlist = Get-TransportService | where-object {$_.name -like $servername} Write-Verbose " Total Servers to process : $($serverlist.count)" [long]$count=0 Foreach ($server in $serverlist) { Write-Verbose " Processing Server $($server.name)" Get-MessageTrackingLog ` -Start $startdate ` -End $Enddate ` -Server $server.name ` -Eventid DSN ` -ResultSize unlimited ` | Select-Object Timestamp,Recipients,MessageSubject,MessageInfo ` | ForEach-Object { $result = [PSCustomObject][ordered]@{ Timestamp = $_.Timestamp Sender = $_.recipients[0] # get sender from the NDRs recipient MessageSubject = $_.MessageSubject Recipient = $_.MessageInfo.split(":")[0].replace("'","") Error = $_.MessageInfo.split(":")[1].replace("'","") } if ($result.error.startswith("<5")) { $count++ $result } } } Write-Verbose "Get-NDRData:TotalNDRs: $($count)" Write-Verbose "Get-NDRData:End"