Skip to content

Commit 9fdce8a

Browse files
committed
Fix argument parsing in wsl-reset binary
Fixes #9
1 parent 5ce9261 commit 9fdce8a

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ To run wsl-dist-update as a service, copy wsl-dist-update.exe to a permanent loc
3737

3838
A troubleshooting utility that resets the WSL 2 stack to various degrees.
3939

40-
`wsl-reset --reset` - Shuts down WSL, resets the WSL service, and installs any WSL updates, if available.
40+
`wsl-reset -reset` - Shuts down WSL, resets the WSL service, and installs any WSL updates, if available.
4141

42-
`wsl-reset --hard-reset` - Shuts down WSL, stops the WSL service, uninstalls WSL, and re-installs WSL.
42+
`wsl-reset -hard-reset` - Shuts down WSL, stops the WSL service, uninstalls WSL, and re-installs WSL.
4343

44-
`wsl-reset --destrutive-reset` - Shuts down WSL, restarts the WSL service, **unregisters all WSL distros**, stops the WSL service, uninstalls WSL, and re-installs WSL.
44+
`wsl-reset -destrutive-reset` - Shuts down WSL, restarts the WSL service, **unregisters all WSL distros**, stops the WSL service, uninstalls WSL, and re-installs WSL.
4545

4646
## sysdistrowt
4747

@@ -51,4 +51,4 @@ Adds the WSL System Distro (CBL-Mariner) to the Windows Terminal and/or Windows
5151

5252
## build-wslinternals
5353

54-
Builds wslinternals PowerShell scripts to .exe files using ps2exe. Requires PowerShell 5.
54+
Builds wslinternals PowerShell scripts to .exe files using ps2exe. Must be run as Administrator on PowerShell 7 or on PowerShell 5.

wsl-reset.ps1

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
param (
2+
[switch]$reset,
3+
[switch]$hardReset,
4+
[switch]$destructiveReset
5+
)
16

27
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
38
Write-Error "This script must be run as an administrator."
49
Exit 1
510
}
611

7-
8-
if (-not $args) {
9-
Write-Error "This script must be run with either --reset, --hard-reset, or --destructive-reset."
10-
Exit 1
11-
}
12-
13-
14-
$arg = $args[0]
15-
switch ($arg) {
16-
"--reset" {
12+
switch ($true) {
13+
$reset {
1714
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
1815
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
1916
if ($LASTEXITCODE -ne 0) {
@@ -22,7 +19,7 @@ switch ($arg) {
2219
wsl.exe --update > $null
2320
Write-Host "WSL has been shutdown, Windows service restarted, and updated, if applicable."
2421
}
25-
"--hard-reset" {
22+
$hardReset {
2623
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
2724
Stop-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
2825
if ($LASTEXITCODE -ne 0) {
@@ -34,7 +31,7 @@ switch ($arg) {
3431
wsl.exe --install --no-launch --no-distribution
3532
Write-Host "WSL has been shutdown and re-installed."
3633
}
37-
"--destructive-reset" {
34+
$destructiveReset {
3835
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
3936
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
4037
if ($LASTEXITCODE -ne 0) {
@@ -55,7 +52,7 @@ switch ($arg) {
5552
Write-Host "WSL has been shutdown, all distros unregistered, and WSL has been re-installed."
5653
}
5754
default {
58-
Write-Error "Invalid argument. This script must be run with either --reset, --hard-reset, or --destructive-reset."
55+
Write-Error "This script must be run with either --reset, --hard-reset, or --destructive-reset."
5956
Exit 1
6057
}
6158
}

0 commit comments

Comments
 (0)