Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Last active December 18, 2024 13:11
Show Gist options
  • Save JonasGroeger/655f038bb05b4d05ec9adb84bc120f9d to your computer and use it in GitHub Desktop.
Save JonasGroeger/655f038bb05b4d05ec9adb84bc120f9d to your computer and use it in GitHub Desktop.
Updates all WSL distributions (assuming all have apt)
$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