You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find-DbaInstance - Fix TcpConnected false for multiple named instances; add verbose messages
The TcpClient in Test-TcpPort was created once (in begin{}) and shared
across all port tests. After the first successful Connect()+Close(), the
client was disposed, causing all subsequent port tests to throw
ObjectDisposedException (caught, returning IsOpen=False).
Fix: create a new TcpClient per port test (moved to process{}) with
Dispose() in a finally block.
Also filter out port 0 from Browser results - DbaBrowserReply.TCPPort
defaults to 0 for instances that don't report a TCP port, and testing
port 0 can leave the socket in an error state.
Added Verbose messages throughout the Browser scan path to aid
debugging: Browser results, port test results, per-instance BrowseReply
TCPPort lookup and outcome.
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
# Fall back to default port testing if Browser returned no port info
359
363
# (e.g. SQL Server 2022+ where Browser is deprecated, or default instances
360
364
# which don't report a TCP port via Browser UDP)
361
365
if (-not$ports) {
366
+
Write-Message-Level Verbose -Message "No port info from Browser, falling back to default ports: $($TCPPort-join', ')"-Target $computer-FunctionName Find-DbaInstance
$object.PortsScanned|Where-Object Port -EQ$object.Port|ForEach-Object {
460
467
$object.TcpConnected=$_.IsOpen
468
+
Write-Message-Level Verbose -Message "Instance $instance: Port $($_.Port) IsOpen=$($_.IsOpen), TcpConnected set to $($object.TcpConnected)"-Target $computer-FunctionName Find-DbaInstance
461
469
}
462
470
} else {
463
471
# Default instance - Browser doesn't report a specific TCP port,
464
472
# check if any of the fallback ports we tested is open
473
+
Write-Message-Level Verbose -Message "Instance $instance: Browser has no TCPPort (default instance), checking PortsScanned for any open port: $(($object.PortsScanned|ForEach-Object { "Port $($_.Port)=$($_.IsOpen)" }) -join', ')"-Target $computer-FunctionName Find-DbaInstance
Write-Message-Level Verbose -Message "Instance $instance: Found open port $($_.Port), TcpConnected set to True"-Target $computer-FunctionName Find-DbaInstance
0 commit comments