Created
September 5, 2020 21:04
-
-
Save danvy/9486bf730371436131cb888ff4c2ceb6 to your computer and use it in GitHub Desktop.
Reset your WSL network connection trying to fix WSL2 media disconnected error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)" |
This works :) I initially copy pasted your code directly into PowerShell terminal and it didn't work. Then I created a separate .ps1 file and ran it and then it worked. Thanks!
This is works.
Thanks
I added
wsl --shutdown wsl ping google.com -c 4
At the end just to check that the wsl internet connection works at the end
This fixed things for me, Thank you!
After 1h30 of trying everything on stackoverflow, this worked ! I am surprised this is still needed and still works after 2 years.
@dtraparic Happy that it help you. I'm also surprised that it's still relevant.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This did the trick for me!