Add warning to collect-wsl-logs.ps1 to be displayed when tool is missing (#14447)
* Added warning message to collect-wsl-logs.ps1 * 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. * Eliminated reduntant parameter and added handling for situation where WSL might be unavailable * Remove try/catch from function's implementation --------- Co-authored-by: Andre Muezerie <andremue@linux.microsoft.com>
Andre Muezerie committed
Apr 15, 2026 at 19:17 UTC
95e2dd94bfa3811063ad690dda3a93143560062f
1 file changed
+41
diagnostics/collect-wsl-logs.ps1
+41
@@ -9,6 +9,44 @@ Param (
9
10
Set-StrictMode -Version Latest
11
12
+function Test-WslApplication {
13
+ param (
14
+ $Name
15
+ )
16
+
17
+ # Log warning when tool is not present in WSL
18
+
19
+ # Capture any output/error from wsl.exe so we can distinguish
20
+ # between "command not found" and "WSL invocation failed".
21
+ $wslOutput = & wsl.exe -e sh -lc "command -v $Name >/dev/null 2>&1" 2>&1
22
+ $exitCode = $LASTEXITCODE
23
+
24
+ if ($exitCode -eq 0)
25
+ {
26
+ return $true
27
+ }
28
+
29
+ # POSIX shells typically return 1 when command -v does not find the command, but we have seen sh returning 127.
30
+ if ($exitCode -eq 1 -or $exitCode -eq 127)
31
+ {
32
+ Write-Warning "$Name not found in WSL. For a more complete log collection install $Name."
33
+ return $false
34
+ }
35
+
36
+ # Any other exit code is assumed to indicate WSL itself failed
37
+ # (e.g., no distro installed, WSL disabled, or other startup error).
38
+ if (-not [string]::IsNullOrWhiteSpace($wslOutput))
39
+ {
40
+ Write-Warning "Unable to check for $Name in WSL. wsl.exe exited with code $exitCode. Output: $wslOutput"
41
+ }
42
+ else
43
+ {
44
+ Write-Warning "Unable to check for $Name in WSL. wsl.exe exited with code $exitCode."
45
+ }
46
+
47
+ return $false
48
+}
49
+
50
function Collect-WindowsNetworkState {
51
param (
52
$Folder,
@@ -89,6 +127,9 @@ else
127
# Networking-specific setup
128
if ($LogProfile -eq "networking")
129
{
130
+ Test-WslApplication -Name "tcpdump" | Out-Null
131
+ Test-WslApplication -Name "iptables" | Out-Null
132
+
133
# Copy/download networking.sh script
134
$networkingBashScript = "$folder/networking.sh"
135
if (Test-Path "$PSScriptRoot/networking.sh")