3 echo "Installing 1 of 5 Microsoft-Windows-Subsystem-Linux (for WSL 1 and WSL 2) ..."
4 & dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
7 echo "Installing 2 of 5 VirtualMachinePlatform (for WSL 2 Hyper-V) ..."
8 & dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
10 Function Test-CommandExists
13 $oldPreference = $ErrorActionPreference
14 $ErrorActionPreference = 'stop'
15 try {if(Get-Command $command){RETURN $true}}
17 Finally {$ErrorActionPreference=$oldPreference}
21 IF(!(Test-CommandExists wsl))
23 echo "Skipping 3 of 5: Microsoft Linux Kernel requires WSL 1 to be installed first ..."
27 echo "Installing 3 of 5 Microsoft Linux Kernel (wsl_update_x64.msi for WSL 2) ..."
28 IF (!(Test-Path -Path "$Env:TEMP\wsl_update_x64.msi")) {
29 & curl.exe -f -o "$Env:TEMP\wsl_update_x64.msi" "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
31 IF (!(Test-Path -Path "C:\Temp\System32\lxss\tools\kernel")) {
32 # NOTE: This WILL NOT work with TARGETDIR=$Env:TEMP!!
33 echo "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'"
34 powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'"
35 echo "Unpacked to C:\Temp\System32\lxss\tools\kernel"
37 Copy-Item -Path "C:\Temp\System32\lxss" -Destination "C:\System32" -Recurse -Force
38 echo "Copied to C:\System32\lxss\tools\kernel ..."
40 echo "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'"
41 powershell -Command "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'"