-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_wsl.ps1
51 lines (38 loc) · 1.99 KB
/
config_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
function Check-SysInfo {
$sysInfo = Get-CimInstance Win32_ComputerSystem
$totalRam = [Math]::Ceiling($sysInfo.TotalPhysicalMemory / 1GB)
$cpuInfo = Get-CimInstance Win32_Processor
$cpuCore = $cpuInfo.NumberOfCores
return $cpuCore, $totalRam
}
function GenerateFile($configPath, $configCPU, $configRam) {
$configContents = "[wsl2]`nmemory=$configRam`GB`nprocessors=$configCPU`nswap=$configRam`GB"
$configContents | Out-File $configPath -Encoding utf8
}
function Configure-WSL($confOption, $cpuCore, $totalRam) {
$configFile = "$env:USERPROFILE\.wslconfig"
$configFileBck = "$env:USERPROFILE\.wslconfig.bck"
if(Test-Path $configFile) {
if(Test-Path $configFileBck) { Remove-Item -Path $configFileBck -Force }
Move-Item -Path $configFile -Destination $configFileBck -Force
}
switch($confOption) {
1 { GenerateFile $configFile $cpuCore $totalRam $totalRam }
2 { GenerateFile $configFile $cpuCore $([Math]::Round($totalRam * 0.8)) }
3 { GenerateFile $configFile $([Math]::Round($cpuCore * 0.8)) $([Math]::Round($totalRam * 0.5)) }
4 { GenerateFile $configFile 1 $([Math]::Floor($cpuCore * 0.5)) $([Math]::Round($totalRam * 0.3)) }
default { Write-Host "Invalid option. Please choose a valid option (between 1-4)." }
}
Write-Host "Generated file $configFile"
}
function main {
Write-Host "`n ____ __ ____ __`n / __/__ / /_/ / /_ _____ / /`n _\ \/ -_) __/_ _/ |/|/ (_-</ /`n/___/\__/\__/ /_/ |__,__/___/_/"
Write-Host "Set4wsl - Auto WSL Configure"
$cpuCore, $totalRam = Check-SysInfo
Write-Host "`nSystem Information`n - CPU: $cpuCore Core`n - RAM: $totalRam GB`n"
Write-Host "Configuration Option`n 1) Full Power`n 2) High Performance`n 3) Balance Control`n 4) Limited Resource"
$confOption = Read-Host "Choose option"
Configure-WSL $confOption $cpuCore $totalRam
Write-Host "`nFinish! If you're running WSL, please restart WSL: wsl --shutdown"
}
main