-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script and instructions to install the latest version of WSL when…
… the machine is in a bad MSIX state (#11500)
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.contains('x64')) | ||
{ | ||
$target = '.x64.msi' | ||
} elseif ($systeminfo.contains('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 |