|
| 1 | +# Cek apakah script dijalankan dengan hak administrator |
| 2 | +if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
| 3 | + Write-Host "Script ini harus dijalankan dengan hak administrator." |
| 4 | + Exit |
| 5 | +} |
| 6 | + |
| 7 | +# Fungsi untuk menjalankan perintah dengan penanganan kesalahan |
| 8 | +function Run-Command { |
| 9 | + param ( |
| 10 | + [string]$command |
| 11 | + ) |
| 12 | + |
| 13 | + try { |
| 14 | + Invoke-Expression -Command $command -ErrorAction Stop |
| 15 | + } catch { |
| 16 | + Write-Host "Error: $_" |
| 17 | + Exit 1 |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +# Install Windows Subsystem for Linux (WSL) |
| 22 | +Run-Command "wsl.exe --install" |
| 23 | + |
| 24 | +# Enable Windows Subsystem for Linux feature |
| 25 | +Run-Command "dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart" |
| 26 | + |
| 27 | +# Enable Virtual Machine Platform feature |
| 28 | +Run-Command "dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart" |
| 29 | + |
| 30 | +# Enable Virtual Machine Platform feature using PowerShell |
| 31 | +Run-Command "Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart" |
| 32 | + |
| 33 | +# Set default WSL version to 2 |
| 34 | +Run-Command "wsl --set-default-version 2" |
| 35 | + |
| 36 | +# Install Ubuntu 22.04 from the Windows Package Manager (winget) |
| 37 | +Run-Command "winget install Canonical.Ubuntu.2204" |
| 38 | + |
| 39 | +# Set WSL version for the Ubuntu 22.04 instance to 2 |
| 40 | +Run-Command "wsl.exe --set-version Canonical.Ubuntu.2204 2" |
| 41 | + |
| 42 | +# List installed WSL distributions |
| 43 | +Run-Command "wsl --list -v" |
| 44 | + |
| 45 | +# Tentukan path ke file MSI yang telah diunduh |
| 46 | +$msiFilePath = "$HOME\Documents\Github\wsl_update_x64.msi" |
| 47 | + |
| 48 | +# Cek apakah file MSI ada |
| 49 | +if (Test-Path $msiFilePath) { |
| 50 | + # Instal file MSI |
| 51 | + Start-Process -Wait -FilePath msiexec.exe -ArgumentList "/i `"$msiFilePath`" /qn" |
| 52 | + Write-Host "Instalasi wsl_update_x64.msi berhasil." |
| 53 | +} else { |
| 54 | + Write-Host "File MSI tidak ditemukan: $msiFilePath" |
| 55 | +} |
| 56 | + |
| 57 | +Write-Host "di sarankan untuk melakukan restart." |
0 commit comments