WARNING: Destructive Script – Use With Extreme Caution!
This PowerShell script completely removes all WSL (Windows Subsystem for Linux) distributions, including:
- All installed distributions (Ubuntu, Debian, Kali, etc.)
- VHD files (
ext4.vhdx,rootfs.vhdx, etc.) - Registry entries related to WSL
- Appx packages and provisioned packages
- ProgramData WSL folders
- Disables WSL-related Windows features (optional)
Important: This script will permanently delete all data inside WSL. Make sure to backup any important files using
wsl --export <distro> file.tarbefore running.
- Stops WSL services safely (
wsl --shutdown) - Unregisters all distributions
- Cleans registry entries (
Lxsskey) - Deletes all VHD files and legacy folders
- Removes common Appx and provisioned packages
- Disables WSL-related Windows features (
VirtualMachinePlatform,Microsoft-Windows-Subsystem-Linux,HypervisorPlatform) - Optional system reboot at the end
- Windows 10 / 11
- PowerShell 5.1+ (built-in)
- Run as Administrator (required for registry, Appx, and Windows features cleanup)
-
Open PowerShell as Administrator.
-
Navigate to the folder containing
remove-all-wsl.ps1:cd "C:\Users\YourUser\Desktop" -
Run the script:
.\remove-all-wsl.ps1
-
Type the confirmation string exactly when prompted:
DELETE_ALL_WSL_NOW -
Wait for the script to complete.
-
Choose to reboot immediately when prompted, or reboot manually later to complete removal.
Before running the script, backup all distributions:
$distros = & wsl --list --quiet
$backupDir = Join-Path $env:USERPROFILE "WSLBackups"
New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
foreach ($d in $distros) {
if (-not [string]::IsNullOrWhiteSpace($d)) {
$file = Join-Path $backupDir "$($d)-$(Get-Date -Format yyyyMMdd_HHmmss).tar"
wsl --export $d $file
}
}
Write-Host "Backups saved to: $backupDir"Restore a backup later with:
wsl --import <NewName> <InstallFolder> <BackupFile.tar>
# Example:
wsl --import UbuntuRestored C:\WSL\UbuntuRestored C:\Users\Khalid ALQarni\WSLBackups\Ubuntu-20250926_101010.tarThis script is destructive. The author is not responsible for any data loss or system issues caused by its use. Use only if you fully understand the consequences.
Free to use for personal purposes. Use at your own risk.