Skip to content

Commit 212838e

Browse files
Merge pull request #11014 from microsoft/user/cfetoiu/add_hns_events
collect-networking-logs.ps1: Collect HNS events and update RestartWslReproMode option
2 parents 96bd92e + 8c6dd56 commit 212838e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

diagnostics/collect-networking-logs.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ if (Test-Path $wslconfig)
3030
if ($RestartWslReproMode)
3131
{
3232
# The WSL HNS network is created once per boot. Resetting it to collect network creation logs.
33-
Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL'} | Remove-HnsNetwork
33+
# Note: The below HNS command applies only to WSL in NAT mode
34+
Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL' -Or $_.Name -eq 'WSL (Hyper-V firewall)'} | Remove-HnsNetwork
3435

3536
# Stop WSL.
3637
net.exe stop WslService
@@ -222,6 +223,14 @@ try
222223
}
223224
catch {}
224225

226+
try
227+
{
228+
# Collect HNS events from past 24 hours
229+
$events = Get-WinEvent -ProviderName Microsoft-Windows-Host-Network-Service | Where-Object { $_.TimeCreated -ge ((Get-Date) - (New-TimeSpan -Day 1)) }
230+
($events | ForEach-Object { '{0},{1},{2},{3}' -f $_.TimeCreated, $_.Id, $_.LevelDisplayName, $_.Message }) -join [environment]::NewLine | Out-File -FilePath "$folder/hns_events.log" -Append
231+
}
232+
catch {}
233+
225234
Remove-Item $logProfile
226235
Remove-Item $networkingBashScript
227236

0 commit comments

Comments
 (0)