From dcf2d4810d9cb153925964753bc3f0d321ecf816 Mon Sep 17 00:00:00 2001 From: Andre Muezerie Date: Fri, 13 Mar 2026 16:54:58 -0400 Subject: [PATCH 1/4] Added warning message to collect-wsl-logs.ps1 --- diagnostics/collect-wsl-logs.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/diagnostics/collect-wsl-logs.ps1 b/diagnostics/collect-wsl-logs.ps1 index 139c3ba4c..45b717415 100644 --- a/diagnostics/collect-wsl-logs.ps1 +++ b/diagnostics/collect-wsl-logs.ps1 @@ -9,6 +9,30 @@ Param ( Set-StrictMode -Version Latest +function Test-WslApplication { + param ( + $Name, + $Command + ) + + # Log warning when tool is not present in WSL + try + { + & wsl.exe -e sh -lc "command -v $Command >/dev/null 2>&1" + $available = ($LASTEXITCODE -eq 0) + + if (-not $available) + { + Write-Warning "$Name not found in WSL. For a more complete log collection install $Name." + } + + return $available + } + catch {} + + return $false +} + function Collect-WindowsNetworkState { param ( $Folder, @@ -89,6 +113,9 @@ else # Networking-specific setup if ($LogProfile -eq "networking") { + Test-WslApplication -Name "tcpdump" -Command "tcpdump --version" | Out-Null + Test-WslApplication -Name "iptables" -Command "iptables --version" | Out-Null + # Copy/download networking.sh script $networkingBashScript = "$folder/networking.sh" if (Test-Path "$PSScriptRoot/networking.sh") From fa217406ffb7bd9b437c77f8c2cf85875c4f0135 Mon Sep 17 00:00:00 2001 From: Andre Muezerie Date: Mon, 16 Mar 2026 16:07:30 -0400 Subject: [PATCH 2/4] Add warning to collect-wsl-logs.ps1 to be displayed when tool is missing On executing the log collection script, it will first confirm the required tools tcpdump and iptables are installed. For each tool missing a warning is displayed, reminding the user that the tool should be installed prior to executing the script to get a more complete log collection. --- diagnostics/collect-wsl-logs.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/diagnostics/collect-wsl-logs.ps1 b/diagnostics/collect-wsl-logs.ps1 index 139c3ba4c..45b717415 100644 --- a/diagnostics/collect-wsl-logs.ps1 +++ b/diagnostics/collect-wsl-logs.ps1 @@ -9,6 +9,30 @@ Param ( Set-StrictMode -Version Latest +function Test-WslApplication { + param ( + $Name, + $Command + ) + + # Log warning when tool is not present in WSL + try + { + & wsl.exe -e sh -lc "command -v $Command >/dev/null 2>&1" + $available = ($LASTEXITCODE -eq 0) + + if (-not $available) + { + Write-Warning "$Name not found in WSL. For a more complete log collection install $Name." + } + + return $available + } + catch {} + + return $false +} + function Collect-WindowsNetworkState { param ( $Folder, @@ -89,6 +113,9 @@ else # Networking-specific setup if ($LogProfile -eq "networking") { + Test-WslApplication -Name "tcpdump" -Command "tcpdump --version" | Out-Null + Test-WslApplication -Name "iptables" -Command "iptables --version" | Out-Null + # Copy/download networking.sh script $networkingBashScript = "$folder/networking.sh" if (Test-Path "$PSScriptRoot/networking.sh") From f36b390625d71a015dd9408e794b625aaea2a746 Mon Sep 17 00:00:00 2001 From: Andre Muezerie Date: Mon, 16 Mar 2026 20:34:21 -0400 Subject: [PATCH 3/4] Eliminated reduntant parameter and added handling for situation where WSL might be unavailable --- diagnostics/collect-wsl-logs.ps1 | 39 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/diagnostics/collect-wsl-logs.ps1 b/diagnostics/collect-wsl-logs.ps1 index 45b717415..3803bc74c 100644 --- a/diagnostics/collect-wsl-logs.ps1 +++ b/diagnostics/collect-wsl-logs.ps1 @@ -11,24 +11,45 @@ Set-StrictMode -Version Latest function Test-WslApplication { param ( - $Name, - $Command + $Name ) # Log warning when tool is not present in WSL try { - & wsl.exe -e sh -lc "command -v $Command >/dev/null 2>&1" - $available = ($LASTEXITCODE -eq 0) + # 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 (-not $available) + 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 } - return $available + # 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 + } + catch + { + Write-Warning "Unexpected error while checking for $Name in WSL." } - catch {} return $false } @@ -113,8 +134,8 @@ else # Networking-specific setup if ($LogProfile -eq "networking") { - Test-WslApplication -Name "tcpdump" -Command "tcpdump --version" | Out-Null - Test-WslApplication -Name "iptables" -Command "iptables --version" | Out-Null + Test-WslApplication -Name "tcpdump" | Out-Null + Test-WslApplication -Name "iptables" | Out-Null # Copy/download networking.sh script $networkingBashScript = "$folder/networking.sh" From 5514f4bb5ba5daf0b226258094055d700902e6df Mon Sep 17 00:00:00 2001 From: Andre Muezerie Date: Tue, 17 Mar 2026 16:47:10 -0400 Subject: [PATCH 4/4] Remove try/catch from function's implementation --- diagnostics/collect-wsl-logs.ps1 | 49 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/diagnostics/collect-wsl-logs.ps1 b/diagnostics/collect-wsl-logs.ps1 index 3803bc74c..cd06d74e0 100644 --- a/diagnostics/collect-wsl-logs.ps1 +++ b/diagnostics/collect-wsl-logs.ps1 @@ -15,40 +15,33 @@ function Test-WslApplication { ) # Log warning when tool is not present in WSL - try - { - # 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 - } + # 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 - # 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 - } + if ($exitCode -eq 0) + { + return $true + } - # 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." - } + # 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 } - catch + + # 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 "Unexpected error while checking for $Name in WSL." + Write-Warning "Unable to check for $Name in WSL. wsl.exe exited with code $exitCode." } return $false