0

I would like to use winget to search for all packages and store them in a text file or a variable. Later on I would like to sort them in a list with "Name" and "ID". Unfortunately it seems like you cannot search just for winget package Names and IDs directly using winget.exe
What I have tried so far:

Clear-Host

if (Test-Path -path "$env:temp\download_winget"){
    write-host "Folder exists. Continuing..."
}
else{
    write-Host "There is no folder called winget_download!`nCreating..."
    mkdir "$env:temp\download_winget"
    
}

$get_winget_packages = winget search . --accept-source-agreements | Out-File "$env:temp\download_winget\winget_packages.txt" -Encoding utf8


(Yes I know, you can also use winget search """")

My Output: (a sample) (using get-content "$env:temp\download_winget\winget_packages.txt")

Name                                      ID                                  Version            Übereinstimmung Quelle
-----------------------------------------------------------------------------------------------------------------------
...
...
...
Windows Package Manager Manifest Creator  Microsoft.WingetCreate              1.1.2.0                            winget
Remote Desktop Services Infrastructure A… Microsoft.WindowsVirtualDesktopAge… 1.0.5739.9800                      winget
Windows Terminal Preview                  Microsoft.WindowsTerminal.Preview   1.16.3463.0                        winget
Windows Admin Center                      Microsoft.WindowsAdminCenter        1.3.53858.0                        winget
Windows Assessment and Deployment Kit     Microsoft.WindowsADK                10.1.22621.1                       winget
...
...
...

As you can see, I displayed with gc "$env:temp\download_winget\winget_packages.txt" the content of the earlier created file. Unfortunately some of the lines are not displayed correctly. For example:

Remote Desktop Services Infrastructure A… Microsoft.WindowsVirtualDesktopAge… 1.0.5739.9800                      winget

I did not find any solution to get all winget packages full Name or full ID using winget search . Even running this directly in PowerShell or CMD, it will display some package Names and ID not fully. Changing the Encoding to utf32, ascii, utf7 or something else wont change anything too.
Is there a workaround to show the correct/full names of all winget packages Name and ID?

I even tried it with a new powershell process with windowstyle maximized:

Start-Process powershell.exe -ArgumentList ("winget search ." , "| Out-File '$env:temp\download_winget\winget_packages_lol.txt' -Encoding utf8") -WindowStyle Maximized

My Output (a sample):

Name                                      ID                                  Version            Übereinstimmung Quelle
-----------------------------------------------------------------------------------------------------------------------
BitRecover Windows Live Mail Converter Wizard         BitRecover.WindowsLiveMailConver 7.5          winget

or

Name                                      ID                                  Version            Übereinstimmung Quelle
-----------------------------------------------------------------------------------------------------------------------
ECLiPSe Constraint Logic Programming System Version  Coninfer.ECLiPSeCLP.7.0           7.0 #63      winget

My next steps would look like this:

$file = gc "$env:temp\download_winget\winget_packages_lol.txt"
$file | sort | Get-Unique | Set-Content "$env:temp\download_winget\winget_packages_lol.txt"

I would also work here with substrings, but as mentioned earlier this can't work if I can't get the full winget packages Name and ID. What can I do here?

Frxhb
  • 41
  • 6
  • How about the powershell winget module? https://www.powershellgallery.com/packages/WinGet – js2010 Jan 17 '23 at 04:47
  • @js2010 I looked it up, but as you can See on https://github.com/ethanbergstrom/winget/issues/12 or https://github.com/ethanbergstrom/winget/issues/2 there is no possibility to do this... maybe there is no solution cause winget-cli just drops .....**$! Output – Frxhb Jan 17 '23 at 14:27
  • Seems like this is a know issue: https://github.com/microsoft/winget-cli/issues/2603 – Frxhb Jan 17 '23 at 15:12
  • 1
    Winget output is a challenge to parse. I'm hoping an official powershell version is on the way. – js2010 Jan 17 '23 at 15:38
  • Maybe set-content would work better than out-file. – js2010 Jan 17 '23 at 18:17
  • How about Cobalt, A PowerShell Crescendo wrapper for WinGet https://www.powershellgallery.com/packages?q=crescendobuilt – js2010 Jan 24 '23 at 02:15

1 Answers1

0

WinGet releases have started including a Microsoft.WinGet.Client powershell module in the "Assets" section.

Demitrius Nelon
  • 1,210
  • 1
  • 10
  • 29