How to display the installed applications in alphabetical order of application name using winget?
Asked Answered
S

5

4

Using winget, Listing applications using winget

winget list command displays the list of the applications currently installed in my computer, but it doesn't display the applications in alphabetical order of application name just like in the control panel,

Program and Features - Control Panel

Is there a way to display the installed applications in alphabetical order of application name using winget?

Note: The two images are from different machines.

Thanks.

Saw answered 23/8, 2022 at 7:12 Comment(1)
There is no sort on the output of list today. The Issue covering sorting output is github.com/microsoft/winget-cli/issues/1155.Jinks
T
8

I was trying to see if there was a parameter/option to accompany the winget command, and really wanted to just comment on the answer by Trenly; I had been using a similar piped command (just shorter), so he should still get the credit!

However, apparently, I must have a certain reputation score to even comment on his (or any other) answer... Yet, I can provide an answer without any rating whatsoever; go figure. So, the shorter version, similar to his answer, but without the unnecessary nested piping:

winget list|Sort-Object
Turkey answered 12/1, 2023 at 10:35 Comment(0)
D
1

As Demetrius mentioned in his comment, there isn't an ability to sort built into the client currently. However, in your screenshot I see you are using PowerShell. You can use PowerShell variables and commands to effectively sort the output. By chaining a few commands together, it is possible to re-create the table. This seemed to work for me -

$a=winget list;$a|select -First 3;$a|select -Skip 3|Sort-Object|select -First 9
Duffel answered 26/9, 2022 at 15:12 Comment(0)
H
1

In command prompt try:

winget list | sort
Helotry answered 19/4 at 0:29 Comment(1)
that was too easy ^_^Ureter
V
0

You can check for ConvertFrom-FixedColumnTable function at here to convert the result of winget list to a table.

I created a function winget_list_OrderBy in order to make it simple:

function winget_list_OrderBy {
    <#
    .EXAMPLE
        winget_list_OrderBy
    .EXAMPLE
        winget_list_OrderBy -OrderBy 'Name' -Arguments "--id=Git.Git"
    #>


    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline)]
        [string[]]
        $OrderBy = 'Name', # $OrderBy can be equal to 'Name'/'Id'/'Version'/'Source' (and 'Available' if exist).

        [Parameter(ValueFromPipeline)]
        [string[]]
        $Arguments = ''
    )
    # Backup the original [Console]::OutputEncoding
    $encoding = [Console]::OutputEncoding
    # Make PowerShell interpret winget.exe's output as UTF-8
    [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

    (winget list $Arguments) -match '^(\p{L}|-)' | # filter out progress-display lines
    ConvertFrom-FixedColumnTable |      # parse output into objects
    Sort-Object $OrderBy |              # sort by the ID property (column)
    Format-Table                        # display the objects in tabular format

    # Restore the original [Console]::OutputEncoding afterwards
    [Console]::OutputEncoding = $encoding

}

Usage is simple: winget_list_OrderBy -OrderBy $OrderBy -Arguments $Arguments or winget_list_OrderBy.

Vinificator answered 27/1, 2023 at 19:14 Comment(0)
S
0

thoughts on this? It may need a little clean up, but I just converted the results to an object Array.

$apps = @("Microsoft Visual Studio Code", "Microsoft Visual Studio Code Insiders", "Visual Studio Community 2022")

$global:foundapps = [System.Collections.Generic.List[object]]::new()
foreach ($app in $apps) {
    $Applist = winget search $app
    $header = $Applist[1]
    $nameposition = $header.indexof('Name')
    $idPosition = $header.indexof('Id')
    $versionPosition = $header.indexof('Version')
    $sourceposition = $header.indexof('Source')
    $name = $header.substring($nameposition, $idPosition).replace(' ', '')
    $id = $header.substring($idPosition, ($versionPosition - $idPosition)).replace(' ', '')
    $iVersiond = $header.substring($versionPosition, ($sourceposition - $versionPosition)).replace(' ', '')
    $source = $header.substring($sourceposition, ($header.length - $sourceposition)).replace(' ', '')
    $appstoadd = $Applist | select-object -skip 3
    foreach ($AppToAdd in $appstoadd) {
        $foundapps.Add([PSCustomObject] @{
                "Name"    = $AppToAdd.substring($nameposition, $idPosition).replace(' ', '')
                "Version" = $AppToAdd.substring($versionPosition, ($sourceposition - $versionPosition)).replace(' ', '')
                "ID"      = $AppToAdd.substring($idPosition, ($versionPosition - $idPosition)).replace(' ', '')
                "Source"  = $AppToAdd.substring($sourceposition, ($header.length - $sourceposition)).replace(' ', '')
            })
    }
}
$foundapps |fl
Sama answered 3/2, 2023 at 22:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.