-
Notifications
You must be signed in to change notification settings - Fork 822
/
install-latest-wsl.ps1
50 lines (39 loc) · 1.32 KB
/
install-latest-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
#Requires -RunAsAdministrator
# This script downloads and installs the latest version of the WSL MSI package
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$release = Invoke-WebRequest 'https://api.github.com/repos/microsoft/WSL/releases/latest' | ConvertFrom-Json
$systeminfo = & systeminfo | findstr /C:"System Type"
if ($systeminfo -like '*x64*')
{
$target = '.x64.msi'
} elseif ($systeminfo -like '*arm64*')
{
$target = '.arm64.msi'
} else
{
throw 'Failed to determine system type ($systeminfo)'
}
[array]$assets = $release.assets | Where-Object { $_.name.ToLower().endswith('.x64.msi')}
if ($assets.count -ne 1)
{
throw 'Failed to find asset ($assets)'
}
$target = "$env:tmp\$($assets.name)"
Write-Host "Downloading $($assets.name) to $target"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','application/octet-stream')
Invoke-WebRequest $assets.url -Out $target -Headers $headers
$MSIArguments = @(
"/i"
$target
"/qn"
"/norestart"
)
$exitCode = (Start-Process -Wait "msiexec.exe" -ArgumentList $MSIArguments -NoNewWindow -PassThru).ExitCode
if ($exitCode -Ne 0)
{
throw "Failed to install package: $exitCode"
}
Write-Host 'Installation complete'
Remove-Item $target -Force