Last active
December 18, 2024 13:11
-
-
Save JonasGroeger/655f038bb05b4d05ec9adb84bc120f9d to your computer and use it in GitHub Desktop.
Updates all WSL distributions (assuming all have apt)
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
$wslDistros = wsl --list --quiet ` | |
| Where-Object { $_.Length -gt 1 } ` # Remove empty lines in output | |
| ForEach-Object { $_ -replace '\x00', '' } # Remove weird nulls after every character in WSL output | |
foreach ($distro in $wslDistros) { | |
Write-Host "Updating $distro" -ForegroundColor Magenta | |
wsl --distribution "$distro" --user root -- sh -c "apt update && apt upgrade -y && apt autoremove -y && apt autoclean" | |
if ($LASTEXITCODE -ne 0) { | |
Write-Host "$distro updated failed." -ForegroundColor Red | |
} else { | |
Write-Host "$distro updated successfully." -ForegroundColor Green | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment