Forum Discussion
Search information in Exchange Receive connector logging
Hi ArjanBroekhuizen,
To collect information about the usage of receive connectors in Exchange using PowerShell, you'll need to parse and consolidate data from multiple log entries. The specific details you mentioned, such as date/time, receive connector name, sending server, sender address, and recipient address, are spread across different lines in the receive logs:
# Define the path to the receive connector log files
$logPath = "C:\Path\To\ReceiveConnectorLogs"
# Define the output file path
$outputFile = "C:\Path\To\Output.csv"
# Initialize an empty array to store the receive connector information
$receiveConnectorInfo = @()
# Get all log files from the log path
$logFiles = Get-ChildItem -Path $logPath -Filter "*.log" -File
# Loop through each log file
foreach ($logFile in $logFiles) {
# Read the content of the log file
$logContent = Get-Content -Path $logFile.FullName
# Loop through each line in the log file
foreach ($line in $logContent) {
# Parse the relevant information from the log line
if ($line -match '(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}).+Receive connector:\s(\S+).+from\s(\S+).+from:\s(\S+)\sto:\s(\S+)') {
$date = $Matches[1]
$receiveConnector = $Matches[2]
$sendingServer = $Matches[3]
$senderAddress = $Matches[4]
$recipientAddress = $Matches[5]
# Create a custom object with the parsed information
$receiveConnectorEntry = [PSCustomObject]@{
Date = $date
ReceiveConnector = $receiveConnector
SendingServer = $sendingServer
SenderAddress = $senderAddress
RecipientAddress = $recipientAddress
}
# Add the custom object to the array
$receiveConnectorInfo += $receiveConnectorEntry
}
}
}
# Export the receive connector information to a CSV file
$receiveConnectorInfo | Export-Csv -Path $outputFile -NoTypeInformation
Before running the script, make sure to update the $logPath variable with the actual path to your receive connector log files, and specify the desired $outputFile path where the consolidated information will be saved.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Kindest regards
Leon Pavesic
Thanks for this comprehensive answer! Later this week I will test the script and will get back the answer.
Kind regards,
Arjan
- ArjanBroekhuizenJul 14, 2023Iron Contributor
Hello @LeoPavesic,
This morning I tried to run the script. But the output came back empty. It looks like the if-statements gets no results.
When I write the content of $LogContent and $line to the commandprompt, it shows me information. But when I do a write-host directly after "if ($line -match...", it is not displays anything.
Do I have to change some values for the if-statement?
Kind regards,
Arjan