Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created January 7, 2022 14:14
Show Gist options
  • Save bill-long/43c0531b48ec09c0360ebf0e387621d2 to your computer and use it in GitHub Desktop.
Save bill-long/43c0531b48ec09c0360ebf0e387621d2 to your computer and use it in GitHub Desktop.
function FindConnectionsWithoutSTARTTLS {
param(
$LocalEndpoint,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('FullName')]
[string[]]$LogFile,
$Header = @('date-time', 'connector-id', 'session-id', 'sequence-number', 'local-endpoint', 'remote-endpoint', 'event', 'data', 'context')
)
begin {
$all = @{}
$startTLS = @{}
$localEndpointIp = $LocalEndpoint.Split(":")[0]
$files = New-Object System.Collections.ArrayList
}
process {
foreach ($file in $LogFile) {
[void]$files.Add($file)
}
}
end {
$filesDone = 0
foreach ($file in $files) {
Write-Progress -Activity "Parsing log files" -Status "$filesDone / $($files.Count)" -PercentComplete ($filesDone * 100 / $files.Count)
Import-Csv $file -Header $Header | % {
if ($_.'local-endpoint' -eq $LocalEndpoint -and $_.'remote-endpoint' -notlike "$($localEndpointIp):*") {
$all[$_.'session-id'] = $_.'remote-endpoint'
if ($_.'data' -eq 'STARTTLS') {
$startTLS[$_.'session-id'] = 1
}
}
}
$filesDone++
}
$all.GetEnumerator() | ? { -not $startTLS.ContainsKey($_.Name) }
}
}
@bill-long
Copy link
Author

image
...
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment