Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions diagnostics/collect-wsl-logs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
Loading