• Stars
    star
    252
  • Rank 161,312 (Top 4 %)
  • Language
    PowerShell
  • License
    GNU General Publi...
  • Created over 2 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2019/2022.

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

  • Requires PowerShell running with Administrator rights
  • Compatible with:
    • Windows 10 (Version 1809 or higher)
    • Windows 11
    • Server 2022
    • Windows Sandbox
  • Not compatible with:
    • Server 2019 (winget not supported)

Features

  • Installs winget-cli directly from PowerShell
  • Always fetches the latest winget version
  • Automatically verifies OS compatibility
  • Determines and installs the appropriate prerequisites based on OS version
  • Supports x86/x64 and arm/arm64 architectures
  • Allows bypassing of existing winget installation verification through -Force parameter or $Force session variable
  • Supports irm/iex one-line command using short URL
  • Supports automatically relaunching in conhost and ending active processes associated with winget that could interfere with the installation
  • Code is hosted on PowerShell Gallery

Script Functionality

  • Identifies processor architecture to decide which prerequisites are needed (x86/x64 or arm/arm64)
  • Checks Windows OS version for compatibility (Windows 10, Windows 11, Server 2022)
  • Verifies Windows 10 release ID for compatibility (must be 1809 or newer)
  • Uses the UI.Xaml and VCLibs as recommended by Microsoft
  • The winget-cli license is downloaded using the latest version from GitHub
  • winget-cli is then installed using the latest version from GitHub
  • Runs command registration if the winget command is not detected at the end of installation

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

  • Before releasing a new version, the script is tested on a clean install of Windows 10 22H2, Server 2022 21H2, and Windows 11 22H2
  • If you run into an issue, please ensure your system is compatible & fully updated
  • Sometimes PowerShell accidentally closes the window before you can read the output, so you can use the -Wait parameter to pause the script for a few seconds before exiting if this is happening on your system
  • Try running winget-install again, sometimes the script will fail due to a temporary issue with the prerequisite server URLs
  • Try using the -Debug parameters to see if it provides any additional information
  • If you're getting a resource in use error message, run the script again with the -ForceClose parameter
  • Try installing winget manually to see if the issue exists with winget itself
  • If the issue occurs when installing winget manually, please open an issue on the winget-cli repo (unrelated to this script)
  • Check the winget-cli Troubleshooting Guide
  • If the problem only occurs when using this script, please open an issue here

Contributing

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

More Repositories

1

Deploy-Office

Easily install the latest version of Microsoft Office 2019, 2021, 2024, Microsoft 365 using a 260 KB installer.
Visual Basic .NET
77
star
2

Root-Certificate-Updater

Update root certificates (and disallowed certificates) on Windows. No changes to settings.
PowerShell
58
star
3

Terminal-Portable

Windows Terminal portable edition.
PowerShell
46
star
4

UninstallTeams

Uninstall Teams in less than a minute.
PowerShell
46
star
5

Extension-Exporter

Chrome extension to export installed extension names and URLs to an HTML file. Reimagined edition of 'Export links of all extensions', now with enhanced security and a redesigned icon.
HTML
27
star
6

UninstallOneDrive

Uninstall OneDrive in less than a minute.
PowerShell
23
star
7

BlockFolderWindowsFirewall

Block all EXEs in a specified folder in Windows Firewall.
PowerShell
20
star
8

choco.run

Install Chocolatey on any computer in one short command using Choco.run!
PowerShell
14
star
9

speedtest

Run a Speedtest.net test from the command line using the official CLI.
PowerShell
10
star
10

GenerateCerts

Generates self-signed SSL/TLS certificates in less than a minute. Uses ECDSA certificates (more secure than RSA). Supports Windows, Linux, and Mac.
C#
10
star
11

DiscordAltF4

Press Alt+F4 to close the Discord window instead of exiting the program.
AutoHotkey
9
star
12

Refresh-EnvironmentVariables

Refreshes/reloads the environment variables in the current PowerShell session
PowerShell
9
star
13

Search-Registry

Search-Registry: Find Keys, Value Names, and Value Data in the Registry
PowerShell
8
star
14

SetExeToRunAsAdmin

Sets an EXE/EXEs to run as administrator.
PowerShell
7
star
15

WinRM-HTTPS-NonDomain-Computers

Automatically configure WinRM with HTTPS at home, or on computers that aren't on a Windows domain.
PowerShell
7
star
16

Install-WindowsTerminal

Install Windows Terminal entirely from PowerShell.
PowerShell
6
star
17

Chocolatey-Package-Updater

Streamline the management of Chocolatey packages by automating version updates, checksum validations, and alert notifications.
PowerShell
6
star
18

MessagesForWeb

Google Messages for Web on Windows. Runs "Messages for web" in a native Windows application. Closes to system tray. Ctrl+Alt+M to show window.
Visual Basic .NET
5
star
19

HideUser

Hide/show users on Windows logon screen.
Visual Basic .NET
5
star
20

IsPortActive

Check if a port is actively listening or in use.
PowerShell
5
star
21

SpawnProcess

Spawns a new process from the command line without blocking execution. Made for Windows. Perfect for running a program/script with a hidden window from Task Scheduler.
Visual Basic .NET
5
star
22

ffmpeg-examples

Examples of common ffmpeg settings / arguments / parameters, especially for video conversion
4
star
23

PowerShell-ContextMenu

Adds PowerShell to the Context Menu in directories on Windows.
PowerShell
4
star
24

ChocolateyPackages

Collection of Chocolatey packages that I maintain.
PowerShell
3
star
25

Used-Car-Inspection-Checklist

Generic list of things to check before purchasing a used car.
2
star
26

Faster-Photoshop

Instantly open Adobe Photoshop. Makes opening Photoshop less time consuming!
AutoHotkey
2
star
27

ClickUp

ClickUp for Windows. Runs ClickUp.com in a native Windows application. Closes to system tray. Alt+Esc to show window.
Visual Basic .NET
2
star
28

ScreenConnect-Scripts

Simple PowerShell scripts to help ScreenConnect / ConnectWise Control start, stop, restart, backup, and update.
PowerShell
2
star
29

RunAsUserInPowerShell

Run a command as a specific user in PowerShell.
1
star
30

Maps-for-Windows

Google Maps for Windows.
Visual Basic .NET
1
star
31

Microsoft-Edge-Uninstaller

Uninstalls all versions of Microsoft Edge
Visual Basic .NET
1
star
32

Add-Prefix-Suffix

Add prefix/suffix to text.
Visual Basic .NET
1
star
33

Terminal-Remover

Removes Windows Terminal and cleans up leftover data. Running this then reinstalling fixes most bugs related to opening Terminal.
Visual Basic .NET
1
star
34

api-keys-hotkey

Press Win+Esc to bring up your API keys, select an API key, press Enter, and your API key is automatically typed into the active window.
AutoHotkey
1
star
35

Simplifi

Simplifi (by Quicken) on Windows. Runs Simplifi in a native Windows application. Closes to system tray. Ctrl+Alt+I to show window.
Visual Basic .NET
1
star
36

exa-linux-install

exa is a modern replacement for "ls" on many flavors of Linux. Although it's available on many distributions, it is not available on all. This repo simply fills in the gaps where exa is not found in certain repos such as Debian 9 and below.
Shell
1
star
37

cwebp-multi

Converts all jpg+png files to webp format in the current directory.
PowerShell
1
star
38

node-modules-script-runner

No more dealing with npm symlinks! Automatically run the right program in respect to the working directory!
Visual Basic .NET
1
star