diff --git a/diagnostics/collect-wsl-logs.ps1 b/diagnostics/collect-wsl-logs.ps1 index 139c3ba4c..cd06d74e0 100644 --- a/diagnostics/collect-wsl-logs.ps1 +++ b/diagnostics/collect-wsl-logs.ps1 @@ -9,6 +9,44 @@ Param ( Set-StrictMode -Version Latest +function Test-WslApplication { + param ( + $Name + ) + + # Log warning when tool is not present in WSL + + # Capture any output/error from wsl.exe so we can distinguish + # between "command not found" and "WSL invocation failed". + $wslOutput = & wsl.exe -e sh -lc "command -v $Name >/dev/null 2>&1" 2>&1 + $exitCode = $LASTEXITCODE + + if ($exitCode -eq 0) + { + return $true + } + + # POSIX shells typically return 1 when command -v does not find the command, but we have seen sh returning 127. + if ($exitCode -eq 1 -or $exitCode -eq 127) + { + Write-Warning "$Name not found in WSL. For a more complete log collection install $Name." + return $false + } + + # Any other exit code is assumed to indicate WSL itself failed + # (e.g., no distro installed, WSL disabled, or other startup error). + if (-not [string]::IsNullOrWhiteSpace($wslOutput)) + { + Write-Warning "Unable to check for $Name in WSL. wsl.exe exited with code $exitCode. Output: $wslOutput" + } + else + { + Write-Warning "Unable to check for $Name in WSL. wsl.exe exited with code $exitCode." + } + + return $false +} + function Collect-WindowsNetworkState { param ( $Folder, @@ -89,6 +127,9 @@ else # Networking-specific setup if ($LogProfile -eq "networking") { + Test-WslApplication -Name "tcpdump" | Out-Null + Test-WslApplication -Name "iptables" | Out-Null + # Copy/download networking.sh script $networkingBashScript = "$folder/networking.sh" if (Test-Path "$PSScriptRoot/networking.sh")