Skip to content

Instantly share code, notes, and snippets.

@szero
Last active February 27, 2024 08:57

Revisions

  1. szero revised this gist Feb 27, 2024. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions install_winget.ps1
    Original file line number Diff line number Diff line change
    @@ -17,19 +17,21 @@ try {

    $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 = "Microsoft.VCLibs.x64.14.00.Desktop.appx"
    $uixaml = "Microsoft.UI.Xaml.2.7.x64.appx"
    $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 https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $vclibs}
    if (!(Test-Path $uixaml)) {Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile $uixaml}
    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
  2. szero revised this gist Feb 10, 2024. No changes.
  3. szero revised this gist Feb 10, 2024. No changes.
  4. szero created this gist Feb 10, 2024.
    45 changes: 45 additions & 0 deletions install_winget.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #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

    $winget = ($wingetdl -split "\/")[-1]
    $license = ($licensedl -split "\/")[-1]
    $vclibs = "Microsoft.VCLibs.x64.14.00.Desktop.appx"
    $uixaml = "Microsoft.UI.Xaml.2.7.x64.appx"


    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 https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $vclibs}
    if (!(Test-Path $uixaml)) {Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -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
    }