Last active
February 27, 2024 08:57
-
-
Save szero/86c91497f4828da02c003cd409bf4f1f to your computer and use it in GitHub Desktop.
Simple script to install winget on Windows 10 and 11 systems, most usefull for people using privacy Windows tools that remove Microsoft Store (must be run with administrator privileges)
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
#Requires -RunAsAdministrator | |
Write-Output "Removing previous instances of winget..." | |
Get-AppxPackage -allUsers *desktopappinstaller* | Remove-AppxPackage | |
Get-AppxPackage -allUsers *winget* | Remove-AppxPackage | |
Write-Output "Getting information on latest winget release..." | |
try { | |
$rel = (Invoke-WebRequest -Uri https://api.github.com/repos/microsoft/winget-cli/releases/latest).Content | Out-String | ConvertFrom-Json | |
} catch { | |
Write-Error $_ | |
Exit | |
} | |
$licensedl = $rel.assets.Where({$_.name -match ".*License1.xml$"}).browser_download_url | |
$wingetdl = $rel.assets.Where({$_.name -match ".*msixbundle$"}).browser_download_url | |
$vclibsdl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" | |
$uixamldl = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx" | |
$winget = ($wingetdl -split "\/")[-1] | |
$license = ($licensedl -split "\/")[-1] | |
$vclibs = ($vclibsdl -split "\/")[-1] | |
$uixaml = ($uixamldl -split "\/")[-1] | |
Write-Output "Downloading WinGet and its dependencies..." | |
if (!(Test-Path $winget)) {Invoke-WebRequest -Uri $wingetdl -OutFile $winget} | |
if (!(Test-Path $license)) {Invoke-WebRequest -Uri $licensedl -OutFile $license} | |
if (!(Test-Path $vclibs)) {Invoke-WebRequest -Uri $vclibsdl -OutFile $vclibs} | |
if (!(Test-Path $uixaml)) {Invoke-WebRequest -Uri $uixamldl -OutFile $uixaml} | |
Add-AppxPackage $vclibs | |
Add-AppxPackage $uixaml | |
Add-AppxPackage $winget | |
Add-AppxProvisionedPackage -Online -PackagePath $winget -LicensePath $license -Verbose | |
Add-AppxPackage -RegisterByFamilyName -MainPackage ([io.fileinfo]$winget).basename | |
Write-Output "Cleaning up downloaded files..." | |
foreach ($file in $winget, $license, $vclibs, $uixaml) { | |
Remove-Item $file -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment