Skip to content

Instantly share code, notes, and snippets.

@h-mochizuki
Created February 6, 2026 13:48
Show Gist options
  • Select an option

  • Save h-mochizuki/f0a40e027792dc003e2a4257dccf2dbf to your computer and use it in GitHub Desktop.

Select an option

Save h-mochizuki/f0a40e027792dc003e2a4257dccf2dbf to your computer and use it in GitHub Desktop.
WSL2のUbuntuを再インストールするバッチファイル
@echo off
setlocal
set PSFILE=%TEMP%\embedded_admin.ps1
> "%PSFILE%" (
echo Write-Host "PowerShell admin mode"
echo Write-Host "Checking installed WSL distributions..."
echo wsl -l -v ^| findstr ^/C:"Ubuntu"
echo Write-Host "Shutting down WSL..."
echo wsl --shutdown
echo Write-Host "Unregistering Ubuntu distribution..."
echo wsl --unregister Ubuntu
echo Write-Host "Reinstalling Ubuntu distribution..."
echo wsl --install -d Ubuntu
)
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile -ExecutionPolicy Bypass -NoExit -File \"%PSFILE%\"'"
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment