From 66a4ce0bf525ccaddd515a98208494c16bbed112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pl=C3=ADnio=20Larrubia?= Date: Sun, 19 Dec 2021 13:23:32 -0300 Subject: [PATCH] Install new WSL Preview for Windows 11+ and uninstall old one (#12) - Windows 10 machines will get an error and do nothing. --- src/scripts/optimize-optional-features.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/scripts/optimize-optional-features.ps1 b/src/scripts/optimize-optional-features.ps1 index f8d2b31..1aaf7f4 100644 --- a/src/scripts/optimize-optional-features.ps1 +++ b/src/scripts/optimize-optional-features.ps1 @@ -61,6 +61,24 @@ function Optimize-OptionalFeatures() { } } + + Try { + + Write-Warning "[?] Installing WSL2 Preview from MS Store for Windows 11+..." + $CheckExistenceBlock = { winget install --source "msstore" --id 9P9TQF7MRM4R --accept-package-agreements } + $err = $null + $err = (Invoke-Expression "$CheckExistenceBlock") | Out-Host + if (($LASTEXITCODE)) { throw $err } # 0 = False, 1 = True + + Write-Host "[-][Features] Uninstalling WSL from Optional Features..." + Get-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" | Where-Object State -Like "Enabled" | Disable-WindowsOptionalFeature -Online -NoRestart + + } + Catch { + + Write-Warning "[?] Couldn't install WSL2 Preview, you must be at least on Windows 11..." + + } } function Main() {