From da25b437563c0ff4bfc0ad6d56746e6fcadc209b Mon Sep 17 00:00:00 2001 From: Catalin-Emil Fetoiu Date: Tue, 31 Oct 2023 11:23:27 -0700 Subject: [PATCH] make script run as standalone --- CONTRIBUTING.md | 9 +++------ diagnostics/collect-networking-logs.ps1 | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a4387e..9eb6e34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -132,12 +132,9 @@ Install [WPR](https://learn.microsoft.com/en-us/windows-hardware/test/wpt/window To collect WSL networking logs, do the following steps in an administrative powershell prompt: ``` -$ Invoke-WebRequest 'https://github.com/microsoft/WSL/archive/refs/heads/master.zip' -OutFile .\wsl.zip -$ Expand-Archive .\wsl.zip .\ -$ Remove-Item .\wsl.zip -$ cd .\WSL-master\diagnostics -$ Set-ExecutionPolicy Bypass -Scope Process -Force -$ .\collect-networking-logs.ps1 +Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-networking-logs.ps1" -OutFile collect-networking-logs.ps1 +Set-ExecutionPolicy Bypass -Scope Process -Force +.\collect-networking-logs.ps1 ``` The script will output when log collection starts. Reproduce the problem, then press any key to stop the log collection. The script will output the path of the log file once done. diff --git a/diagnostics/collect-networking-logs.ps1 b/diagnostics/collect-networking-logs.ps1 index 23553e2..56b2900 100644 --- a/diagnostics/collect-networking-logs.ps1 +++ b/diagnostics/collect-networking-logs.ps1 @@ -8,6 +8,13 @@ Param ( $folder = "WslNetworkingLogs-" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss") mkdir -p $folder +$logProfile = "$folder/wsl_networking.wprp" +$networkingBashScript = "$folder/networking.sh" + +# Download supporting files +Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/wsl_networking.wprp" -OutFile $logProfile +Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/networking.sh" -OutFile $networkingBashScript + # Retrieve WSL version and wslconfig file get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpackage.txt @@ -18,7 +25,7 @@ if (Test-Path $wslconfig) } # Collect Linux network state before the repro -& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_before.log +& wsl.exe -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_before.log if ($RestartWslReproMode) { @@ -34,7 +41,6 @@ if ($RestartWslReproMode) } # Start logging. -$logProfile = ".\wsl_networking.wprp" $wprOutputLog = "$folder/wpr.txt" wpr.exe -start $logProfile -filemode 2>&1 >> $wprOutputLog @@ -123,7 +129,7 @@ finally } # Collect Linux network state after the repro -& wsl.exe -e ./networking.sh 2>&1 > $folder/linux_network_configuration_after.log +& wsl.exe -e $networkingBashScript 2>&1 > $folder/linux_network_configuration_after.log # Collect host networking state relevant for WSL # Using a try/catch for commands below, as some of them do not exist on all OS versions @@ -216,6 +222,9 @@ try } catch {} +Remove-Item $logProfile +Remove-Item $networkingBashScript + $logArchive = "$(Resolve-Path $folder).zip" Compress-Archive -Path $folder -DestinationPath $logArchive Remove-Item $folder -Recurse