Skip to content

Instantly share code, notes, and snippets.

@crutkas
Last active November 20, 2023 04:13
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save crutkas/6c2096eae387e544bd05cde246f23901 to your computer and use it in GitHub Desktop.
Save crutkas/6c2096eae387e544bd05cde246f23901 to your computer and use it in GitHub Desktop.
InstallWinGet PowerShell
function InstallWinGet()
{
$hasPackageManager = Get-AppPackage -name "Microsoft.DesktopAppInstaller"
if(!$hasPackageManager)
{
$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releases = Invoke-RestMethod -uri "$($releases_url)"
$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith("msixbundle") } | Select -First 1
Add-AppxPackage -Path $latestRelease.browser_download_url
}
}
<#
Add-AppxPackage -Path "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releases = Invoke-RestMethod -uri "$($releases_url)"
$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith("appxbundle") } | Select -First 1
Add-AppxPackage -Path $latestRelease.browser_download_url
#>
@ecofriend
Copy link

ecofriend commented Jun 30, 2021

Doesn't seem to work anymore. If I put the following on a system that doesn't have winget

$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$releases = Invoke-RestMethod -uri "$($releases_url)"

$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith("msixbundle") } | Select -First 1
	Add-AppxPackage -Path $latestRelease.browser_download_url

I get the following error:

Add-AppxPackage : Cannot process argument transformation on parameter 'Path'. Object reference not set to an instance of an object.
At line:11 char:31
Add-AppxPackage -Path $latestRelease.browser_download_url

CategoryInfo          : InvalidData: (:) [Add-AppxPackage], ParameterBindingArgumentTransformationException
FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

@crutkas
Copy link
Author

crutkas commented Jun 30, 2021

what version of windows are you on?

if you did

$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releases = Invoke-RestMethod -uri "$($releases_url)"
$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith("msixbundle") } | Select -First 1
	
$latestRelease.browser_download_url

What is outputted? Mine is https://github.com/microsoft/winget-cli/releases/download/v1.0.11692/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

@ecofriend
Copy link

Thanks for the quick reply, Clint. I'm on 21H1,

Full info:
Edition Windows 10 Pro
Version 21H1
Installed on ‎6/‎28/‎2021
OS build 19043.1081
Experience Windows Feature Experience Pack 120.2212.3530.0

@ecofriend
Copy link

what version of windows are you on?

if you did

$releases_url = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releases = Invoke-RestMethod -uri "$($releases_url)"
$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith("msixbundle") } | Select -First 1
	
$latestRelease.browser_download_url

What is outputted? Mine is https://github.com/microsoft/winget-cli/releases/download/v1.0.11692/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

I get the same output

https://github.com/microsoft/winget-cli/releases/download/v1.0.11692/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

@crutkas
Copy link
Author

crutkas commented Jul 7, 2021

Try just the “Add-AppxPackage -Path “ with that url.

@rackeshnavale87
Copy link

rackeshnavale87 commented Aug 25, 2021

How can I install this with Local System account. (I am trying to install winget on the remote Azure VM)
Error while trying to install winget using above script from Azure portal (using RunPowerShellScript for the VM)

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CF9, Install failed. Please contact your software vendor.
(Exception from HRESULT: 0x80073CF9)
Deployment Add operation rejected on package Microsoft.DesktopAppInstaller_2021.618.1855.0_neutral_~_8wekyb3d8bbwe
from: Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle install request because the Local System account is not
allowed to perform this operation.
NOTE: For additional information, look for [ActivityId] 6e54f4ed-76ae-0002-c58c-71cac692d701 in the Event Log or use
the command line Get-AppPackageLog -ActivityID 6e54f4ed-76ae-0002-c58c-71cac692d701
At C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.8\Downloads\script8.ps1:9 char:3

  • Add-AppxPackage -Path $latestRelease.browser_download_url
+ CategoryInfo          : WriteError: (https://github....bbwe.msixbundle:String) [Add-AppxPackage], IOException
+ FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

@hoang-himself
Copy link

Why go such length?

Add-AppxPackage -Path 'https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment