WingetTools PowerShell Module

repository·main·Indexed 41 days ago

https://github.com/jdhitsolutions/wingettools

A PowerShell module providing a wrapper around the Microsoft winget command-line tool. It converts text-based winget output into structured PowerShell objects to simplify automation, filtering, and package management. Key cmdlets include Get-WGPackage, Get-WGInstalled, Get-WGUpgrade, Invoke-WGUpgrade, and Install-WinGet. Compatible with Windows PowerShell 5.1 and PowerShell 7.x on Windows 10 and 11.

Tokens
8.2K
Snippets
44
Records
60
Agent score
46%

What's inside WingetTools

  1. Install winget using Install-WinGet

    main
    If winget is not available via the Microsoft Store, you can use Install-WinGet to download and install the latest version from GitHub. This command must be executed in a Windows PowerShell session on Windows 10 or Windows 11. It automatically handles the DesktopAppInstaller dependency if it is missing.
    Install-WinGet
  2. Identify and upgrade packages with Get-WGUpgrade and Invoke-WGUpgrade

    main

    WingetTools provides a workflow for managing package upgrades using PowerShell objects.

    1. Identify Upgrades: Use Get-WGUpgrade to generate a list of packages that have available updates. It outputs custom objects formatted as a table by default.
    2. Perform Upgrades:
      • Option A (Manual Loop): Pipe the output of Get-WGUpgrade to a ForEach-Object loop that calls winget.exe upgrade --id <ID>.
      • Option B (Recommended): Pipe the output of Get-WGUpgrade directly to Invoke-WGUpgrade. This command is a wrapper that uses the package ID and applies silent install options, automatically accepting all licenses and agreements. It also supports the -WhatIf parameter for safe testing.
  3. Install the WingetTools module

    main

    Install the WingetTools module from the PowerShell Gallery. This module is a PowerShell wrapper around the winget command-line tool, designed to make winget more PowerShell-friendly by converting console output into custom objects.

    It works in Windows PowerShell 5.1 and PowerShell 7.x on Windows. Installing this module will also install its dependencies: ThreadJob and psyml.

    Install-Module WingetTools
  4. Install WinGet via Install-WinGet

    main

    Use the Install-WinGet cmdlet to download and install the latest WinGet release from GitHub. This is useful if WinGet is not yet available to you via the Microsoft Store.

    Requirements & Behavior:

    • Must be run in a Windows PowerShell session on Windows 10 or Windows 11.
    • The command automatically checks for the Microsoft.VCLibs.140.00.UWPDesktop package. If it is missing, the command will download and install it automatically.
    Install-WinGet
  5. Install WinGet via PowerShell

    main

    If winget is not available via the Microsoft Store, you can install the latest version from GitHub.

    Requirements:

    • This command must be run in a Windows PowerShell session (not PowerShell 7).
    • Must be run on Windows 10 or Windows 11.
    • The winget package requires the DesktopAppInstaller package; if not found locally, it will be downloaded and installed automatically.
  6. Install the latest Winget version via Install-WinGet

    main

    Use the Install-WinGet cmdlet to download and install the latest version of Winget directly from GitHub. This is useful if Winget is not yet available via the Microsoft Store on your system.

    Requirements:

    • Must be executed in a Windows PowerShell session.
    • Operating System: Windows 10 or Windows 11.
    • Dependency: The package requires Microsoft.VCLibs.140.00.UWPDesktop. If this dependency is missing, the cmdlet will attempt to download and install it automatically.

    Usage: Run the command without parameters for a standard installation, or use the -Preview flag to install the latest preview build.

    Install-WinGet
  7. Install-WinGet

    main

    Use Install-WinGet to install the latest version of the winget command-line tool from GitHub. This is useful if winget is not yet publicly available via the Microsoft Store on your system.

    Requirements:

    • Must be run in a Windows PowerShell session.
    • Compatible with Windows 10 or Windows 11.
    • Requires the DesktopAppInstaller package (the command will attempt to download and install it if it is missing).
    Install-WinGet
  8. Use the update view with Get-WGInstalled results

    main

    Once you have captured the output of Get-WGInstalled into a variable, you can use the format-table -view update command to quickly identify which installed packages have available updates. This view provides a comparison between InstalledVersion and OnlineVersion, along with a boolean Update flag.

    $in | format-table -view update
  9. Pipe upgrades to Invoke-WGUpgrade

    main

    You can pipe objects from Get-WGUpgrade directly into Invoke-WGUpgrade. This allows for filtering or interactive selection before performing the upgrade.

    Filter and simulate: Use Get-WGUpgrade with a name filter and pipe to Invoke-WGUpgrade -WhatIf to see what would happen without actually performing the upgrade.

    Interactive selection: Pipe Get-WGUpgrade to Out-GridView -OutputMode Multiple to select specific packages from a GUI window, then pipe those selections to Invoke-WGUpgrade to install only the chosen items.

    # Simulate upgrades for packages starting with 'p'
    Get-WGUpgrade -Name p* | Invoke-WGUpgrade -WhatIf
    
    # Select specific upgrades via a GUI and then install them
    Get-WGUpgrade | Out-GridView -OutputMode Multiple | Invoke-WGUpgrade
  10. Pipe winget search results to Get-WGPackage

    main

    You can combine standard winget CLI commands with Get-WGPackage to transform text-based search results into structured PowerShell objects. This is useful for filtering or selecting specific properties from a search result set.

    winget search --tag powerbi | Get-WGPackage | Select-Object Name,ID,Version