Various improvements to collect-wsl-logs.ps1 (#9731)
Blue committed
Mar 6, 2023 at 09:44 UTC
5db50890d53406b9910026b4b7a4c8cfcd29d3e1
1 file changed
+56
-38
diagnostics/collect-wsl-logs.ps1
+56
-38
@@ -37,48 +37,66 @@ get-appxpackage MicrosoftCorporationII.WindowsSubsystemforLinux > $folder/appxpa
37
get-acl "C:\ProgramData\Microsoft\Windows\WindowsApps" -ErrorAction Ignore | Format-List > $folder/acl.txt
38
Get-WindowsOptionalFeature -Online > $folder/optional-components.txt
39
40
-wpr.exe -start $LogProfile -filemode
41
-
42
-Write-Host -NoNewLine -ForegroundColor Green "Log collection is running. Please reproduce the problem and press any key to save the logs."
43
-
44
-$KeysToIgnore =
45
- 16, # Shift (left or right)
46
- 17, # Ctrl (left or right)
47
- 18, # Alt (left or right)
48
- 20, # Caps lock
49
- 91, # Windows key (left)
50
- 92, # Windows key (right)
51
- 93, # Menu key
52
- 144, # Num lock
53
- 145, # Scroll lock
54
- 166, # Back
55
- 167, # Forward
56
- 168, # Refresh
57
- 169, # Stop
58
- 170, # Search
59
- 171, # Favorites
60
- 172, # Start/Home
61
- 173, # Mute
62
- 174, # Volume Down
63
- 175, # Volume Up
64
- 176, # Next Track
65
- 177, # Previous Track
66
- 178, # Stop Media
67
- 179, # Play
68
- 180, # Mail
69
- 181, # Select Media
70
- 182, # Application 1
71
- 183 # Application 2
72
-
73
-$Key = $null
74
-while ($Key -Eq $null -Or $Key.VirtualKeyCode -Eq $null -Or $KeysToIgnore -Contains $Key.VirtualKeyCode)
40
+$wprOutputLog = "$folder/wpr.txt"
41
+
42
+wpr.exe -start $LogProfile -filemode 2>&1 >> $wprOutputLog
43
+if ($LastExitCode -Ne 0)
44
{
76
- $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
45
+ Write-Host -ForegroundColor Yellow "Log collection failed to start (exit code: $LastExitCode), trying to reset it."
46
+ wpr.exe -cancel 2>&1 >> $wprOutputLog
47
+
48
+ wpr.exe -start $LogProfile -filemode 2>&1 >> $wprOutputLog
49
+ if ($LastExitCode -Ne 0)
50
+ {
51
+ Write-Host -ForegroundColor Red "Couldn't start log collection (exitCode: $LastExitCode)"
52
+ }
53
}
54
79
-Write-Host "`nSaving logs..."
55
+try
56
+{
57
+ Write-Host -NoNewLine -ForegroundColor Green "Log collection is running. Please reproduce the problem and press any key to save the logs."
58
+
59
+ $KeysToIgnore =
60
+ 16, # Shift (left or right)
61
+ 17, # Ctrl (left or right)
62
+ 18, # Alt (left or right)
63
+ 20, # Caps lock
64
+ 91, # Windows key (left)
65
+ 92, # Windows key (right)
66
+ 93, # Menu key
67
+ 144, # Num lock
68
+ 145, # Scroll lock
69
+ 166, # Back
70
+ 167, # Forward
71
+ 168, # Refresh
72
+ 169, # Stop
73
+ 170, # Search
74
+ 171, # Favorites
75
+ 172, # Start/Home
76
+ 173, # Mute
77
+ 174, # Volume Down
78
+ 175, # Volume Up
79
+ 176, # Next Track
80
+ 177, # Previous Track
81
+ 178, # Stop Media
82
+ 179, # Play
83
+ 180, # Mail
84
+ 181, # Select Media
85
+ 182, # Application 1
86
+ 183 # Application 2
87
+
88
+ $Key = $null
89
+ while ($Key -Eq $null -Or $Key.VirtualKeyCode -Eq $null -Or $KeysToIgnore -Contains $Key.VirtualKeyCode)
90
+ {
91
+ $Key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
92
+ }
93
81
-wpr.exe -stop $folder/logs.etl
94
+ Write-Host "`nSaving logs..."
95
+}
96
+finally
97
+{
98
+ wpr.exe -stop $folder/logs.etl 2>&1 >> $wprOutputLog
99
+}
100
101
if ($Dump)
102
{