Skip to content

Instantly share code, notes, and snippets.

@maddbuzz
Forked from danvy/WSL2-Net-Fix.ps1
Created December 28, 2024 13:57
Show Gist options
  • Save maddbuzz/e6bee70d9f4abc8ff49c9c0407d58110 to your computer and use it in GitHub Desktop.
Save maddbuzz/e6bee70d9f4abc8ff49c9c0407d58110 to your computer and use it in GitHub Desktop.
Reset your WSL network connection trying to fix WSL2 media disconnected error
# Check these threads before proceeding:
# https://github.com/microsoft/WSL/discussions/5857
# https://github.com/microsoft/WSL/issues/5821
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
$CmdLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CmdLine
Exit
}
# Restart the Host Network Service
Restart-Service -Force -Name hns
# Restart the Windows Subsystem for Linux Manager
Restart-Service LxssManager
# Restart the WSL Network adapter
Restart-NetAdapter -Name "vEthernet (WSL)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment