From 56e7ee2dcb5da7cae69993eb1ac1a5d46644c1be Mon Sep 17 00:00:00 2001 From: Hayden Barnes Date: Sun, 12 Nov 2023 11:00:47 -0700 Subject: [PATCH] Add hcs container killing to -hard-reset and -destructive-reset --- wsl-reset.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wsl-reset.ps1 b/wsl-reset.ps1 index 503198b..b2d6d01 100644 --- a/wsl-reset.ps1 +++ b/wsl-reset.ps1 @@ -28,6 +28,12 @@ switch ($true) { if (-not (Get-AppxPackage *WindowsSubsystemForLinux* | Remove-AppxPackage -ErrorAction SilentlyContinue 2>$null)) { Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -ErrorAction SilentlyContinue 2>$null } + $containersJson = & hcsdiag list -raw + $containers = $containersJson | ConvertFrom-Json + $containerGuids = $containers | ForEach-Object { $_.Id } + foreach ($containerGuid in $containerGuids) { + & hcsdiag kill $containerGuid + } wsl.exe --install --no-launch --no-distribution Write-Host "WSL has been shutdown and re-installed." } @@ -48,6 +54,12 @@ switch ($true) { if (-not (Get-AppxPackage *WindowsSubsystemForLinux* | Remove-AppxPackage -ErrorAction SilentlyContinue 2>$null)) { Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -ErrorAction SilentlyContinue 2>$null } + $containersJson = & hcsdiag list -raw + $containers = $containersJson | ConvertFrom-Json + $containerGuids = $containers | ForEach-Object { $_.Id } + foreach ($containerGuid in $containerGuids) { + & hcsdiag kill $containerGuid + } wsl.exe --install --no-launch --no-distribution Write-Host "WSL has been shutdown, all distros unregistered, and WSL has been re-installed." }