-
Notifications
You must be signed in to change notification settings - Fork 11
/
provision-wsl2.ps1
35 lines (31 loc) · 1.48 KB
/
provision-wsl2.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
# see https://ubuntu.com/blog/ubuntu-on-wsl-2-is-generally-available
# see https://aka.ms/wsl2kernel
# only install WSL2 in Windows 2004+ Client/Workstation.
# see https://github.com/microsoft/WSL/issues/6301#issuecomment-858816891
$windowsCurrentVersionKey = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$windowsEdition = $windowsCurrentVersionKey.EditionID
if ($windowsEdition -like 'Server*') {
Write-Host "WARN: WSL was skipped because it only works in the Client/Workstation Windows edition. The current Windows edition is $windowsEdition."
Exit 0
}
$windowsBuildNumber = $windowsCurrentVersionKey.CurrentBuildNumber
if ($windowsBuildNumber -lt 19041) {
Write-Host "WARN: WSL2 was skipped because you need Windows Build 19041+ (aka Windows 10 2004) and you are using Windows Build $windowsBuildNumber."
Exit 0
}
Write-Host 'Downloading the WSL2 kernel...'
$archiveUrl = 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi'
$archiveName = Split-Path -Leaf $archiveUrl
$archivePath = "$env:TEMP\$archiveName"
(New-Object System.Net.WebClient).DownloadFile($archiveUrl, $archivePath)
Write-Host 'Installing the WSL2 kernel...'
msiexec /i $archivePath `
/qn `
/L*v "$archivePath.log" `
| Out-String -Stream
if ($LASTEXITCODE) {
throw "$archiveName installation failed with exit code $LASTEXITCODE. See $archivePath.log."
}
Remove-Item $archivePath
Write-Host 'Setting default WSL version to 2...'
wsl.exe --set-default-version 2