Created
June 17, 2025 15:46
-
-
Save JonathanLalou/c07462321a2993596069676e2a7996f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# ===================================================== | |
# WSL Full Reset Script for Windows 11 | |
# Removes all distros and resets WSL system features | |
# MUST BE RUN AS ADMINISTRATOR | |
# ===================================================== | |
Write-Host "`n== STEP 1: List and remove all WSL distros ==" -ForegroundColor Cyan | |
$distros = wsl --list --quiet | |
foreach ($distro in $distros) { | |
Write-Host "Unregistering WSL distro: $distro" -ForegroundColor Yellow | |
wsl --unregister "$distro" | |
} | |
Start-Sleep -Seconds 2 | |
Write-Host "`n== STEP 2: Disable WSL-related Windows features ==" -ForegroundColor Cyan | |
dism.exe /online /disable-feature /featurename:VirtualMachinePlatform /norestart | |
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart | |
Start-Sleep -Seconds 2 | |
Write-Host "`n== STEP 3: Uninstall WSL kernel update (if present) ==" -ForegroundColor Cyan | |
$wslUpdate = Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*Microsoft.WSL2*" } | |
if ($wslUpdate) { | |
winget uninstall --id "Microsoft.WSL2" --silent | |
} else { | |
Write-Host "No standalone WSL kernel update found." -ForegroundColor DarkGray | |
} | |
Start-Sleep -Seconds 2 | |
Write-Host "`n== STEP 4: Clean leftover configuration files ==" -ForegroundColor Cyan | |
$paths = @( | |
"$env:USERPROFILE\.wslconfig", | |
"$env:APPDATA\Microsoft\Windows\WSL", | |
"$env:LOCALAPPDATA\Packages\CanonicalGroupLimited*", | |
"$env:LOCALAPPDATA\Docker", | |
"$env:USERPROFILE\.docker" | |
) | |
foreach ($path in $paths) { | |
Write-Host "Removing: $path" -ForegroundColor DarkYellow | |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $path | |
} | |
Write-Host "`n== STEP 5: Reboot Required ==" -ForegroundColor Magenta | |
Write-Host "Please restart your computer to complete the WSL reset process." | |
# Optional: Reinstall WSL cleanly (after reboot) | |
# Uncomment the lines below if you want the script to also reinstall WSL | |
<# | |
Write-Host "`n== STEP 6: Reinstall WSL ==" -ForegroundColor Cyan | |
wsl --install | |
#> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment