Merge pull request #11014 from microsoft/user/cfetoiu/add_hns_events

collect-networking-logs.ps1: Collect HNS events and update RestartWslReproMode option
This commit is contained in:
Cătălin Emil Fetoiu 2024-01-12 17:16:31 -08:00 committed by GitHub
commit 212838e05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,8 @@ if (Test-Path $wslconfig)
if ($RestartWslReproMode)
{
# The WSL HNS network is created once per boot. Resetting it to collect network creation logs.
Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL'} | Remove-HnsNetwork
# Note: The below HNS command applies only to WSL in NAT mode
Get-HnsNetwork | Where-Object {$_.Name -eq 'WSL' -Or $_.Name -eq 'WSL (Hyper-V firewall)'} | Remove-HnsNetwork
# Stop WSL.
net.exe stop WslService
@ -222,6 +223,14 @@ try
}
catch {}
try
{
# Collect HNS events from past 24 hours
$events = Get-WinEvent -ProviderName Microsoft-Windows-Host-Network-Service | Where-Object { $_.TimeCreated -ge ((Get-Date) - (New-TimeSpan -Day 1)) }
($events | ForEach-Object { '{0},{1},{2},{3}' -f $_.TimeCreated, $_.Id, $_.LevelDisplayName, $_.Message }) -join [environment]::NewLine | Out-File -FilePath "$folder/hns_events.log" -Append
}
catch {}
Remove-Item $logProfile
Remove-Item $networkingBashScript