Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Remove All WSL Script

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.tar before running.


Features

  • Stops WSL services safely (wsl --shutdown)
  • Unregisters all distributions
  • Cleans registry entries (Lxss key)
  • 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

Requirements

  • Windows 10 / 11
  • PowerShell 5.1+ (built-in)
  • Run as Administrator (required for registry, Appx, and Windows features cleanup)

Usage

  1. Open PowerShell as Administrator.

  2. Navigate to the folder containing remove-all-wsl.ps1:

    cd "C:\Users\YourUser\Desktop"
  3. Run the script:

    .\remove-all-wsl.ps1
  4. Type the confirmation string exactly when prompted:

    DELETE_ALL_WSL_NOW
    
  5. Wait for the script to complete.

  6. Choose to reboot immediately when prompted, or reboot manually later to complete removal.


Backup (Recommended)

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.tar

Disclaimer

This 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.


License

Free to use for personal purposes. Use at your own risk.

About

PowerShell script completely removes all WSL (Windows Subsystem for Linux) distributions

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages