asheroto / winget-install

Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2019/2022.
https://bit.ly/winget-install
GNU General Public License v3.0
272 stars 33 forks source link
auto automatically cli cmd dependencies dependency fix install installer microsoft msix msixbundle powershell prerequisites script windows winget xaml

winget Windows 10

PowerShell Gallery Downloads GitHub Downloads - All Releases Release GitHub Release Date - Published_At

GitHub Sponsor Ko-Fi Button

Install winget from PowerShell

winget, a command line package manager, doesn't have a command line installer? 🤣 Now it does! 😊

[!NOTE] Microsoft released some new short URLs that work well for installing winget. This is the new script that is smaller and faster at installing winget!

Table of Contents

Requirements

[!NOTE] Server 2019 is now supported thanks to MatthiasGuelck in PR #43.

Features

Script Functionality

Setup

Method 1 - PowerShell Gallery

[!TIP] If you want to trust PSGallery so you aren't prompted each time you run this command, or if you're scripting this and want to ensure the script isn't interrupted the first time it runs...

Install-PackageProvider -Name "NuGet" -Force
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

This is the recommended method, because it always gets the public release that has been tested, it's easy to remember, and supports all parameters.

Open PowerShell as Administrator and type

Install-Script winget-install -Force

Follow the prompts to complete the installation (you can tap A to accept all prompts or Y to select them individually.

Note: -Force is optional but recommended, as it will force the script to update if it is outdated. If you do not use -Force, it will not overwrite the script if outdated.

Usage

winget-install

If winget is already installed, you can use the -Force parameter to force the script to run anyway.

The script is published on PowerShell Gallery under winget-install.

Method 2 - One Line Command (Runs Immediately)

The URL asheroto.com/winget always redirects to the latest code-signed release of the script.

If you just need to run the basic script without any parameters, you can use the following one-line command:

Option A: asheroto.com short URL

irm asheroto.com/winget | iex

Due to the nature of how PowerShell works, you won't be able to use any parameters like -Force with this command line. You can set the global variable $Force to $true and the script should pick up on it (more info), but if for some reason that doesn't work or you absolutely need to use a one-line command with parameters, you can use the following:

&([ScriptBlock]::Create((irm asheroto.com/winget))) -Force

Option B: winget.pro short URL

To make it easier to remember, you can also use the URL winget.pro which redirects to the same URL. This URL is provided courtesy of Omaha Consulting.

irm winget.pro | iex

Due to the nature of how PowerShell works, you won't be able to use any parameters like -Force with this command line. You can set the global variable $Force to $true and the script should pick up on it (more info), but if for some reason that doesn't work or you absolutely need to use a one-line command with parameters, you can use the following:

&([ScriptBlock]::Create((irm winget.pro))) -Force

Option C: direct release URL

Alternatively, you can of course use the latest code-signed release URL directly:

irm https://github.com/asheroto/winget-install/releases/latest/download/winget-install.ps1 | iex

Method 3 - Download Locally and Run

As a more conventional approach, download the latest winget-install.ps1 from Releases, then run the script as follows:

.\winget-install.ps1

You can use the -Force or -ForceClose parameters if needed, or use $Force = $true and $ForceClose = $true global session variables if preferred.

[!TIP] If for some reason your PowerShell window closes at the end of the script and you don't want it to, or don't want your other scripts to be interrupted, you can wrap the command in a powershell "COMMAND HERE". For example, powershell "irm asheroto.com/winget | iex".

Parameters

No parameters are required to run the script, but there are some optional parameters to use if needed.

Parameter Description
-Debug Enables debug mode, which shows additional information for debugging.
-Force Ensures installation of winget and its dependencies, even if already present.
-ForceClose Windows Terminal sometimes has trouble installing winget; run the script with the -ForceClose parameter to relaunch the script in conhost.exe and automatically end active processes associated with winget that could interfere with the installation
-CheckForUpdate Checks if there is an update available for the script.
-Wait By default, the script will exit immediately after completion. If you need some time to observe the script output, you can use this parameter to force the script to pause for several seconds before exiting.
-UpdateSelf Updates the script to the latest version.
-Version Displays the version of the script.
-Help Displays the full help information for the script.

Example Parameters Usage

winget-install -Force

Global Variables

Global variables are optional and are only needed if you don't want to use parameters. They can be set before running the script, or you can set them in your PowerShell profile to always use them.

Variable Description
$Debug Enables debug mode, which shows additional information for debugging.
$Force Ensures installation of winget and its dependencies, even if already present.
$ForceClose Windows Terminal sometimes has trouble installing winget; run the script with the -ForceClose parameter to relaunch the script in conhost.exe and automatically end active processes associated with winget that could interfere with the installation

Example Global Variables Usage

$Force = $true
winget-install

Troubleshooting

Contributing

If you'd like to help develop this project: fork the repo, edit the code, then submit a pull request. 😊

To do list