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