3

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.

suravshrestha
  • 329
  • 1
  • 5
  • 14
  • 1
    There is no sort on the output of list today. The Issue covering sorting output is https://github.com/microsoft/winget-cli/issues/1155. – Demitrius Nelon Sep 13 '22 at 15:56

4 Answers4

3

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

AIS Pros
  • 31
  • 3
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
Trenly
  • 158
  • 6
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.

NJT145
  • 3
  • 2
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