I have been trying to write a script that will first run the
winget upgrade --all --accept-package-agreements --accept-source-agreements --silent
command and then log the results of it. Meaning that there will be packages that will fail to install due to hash mismatch - this is OK for me - and there will be ones that will be installed without issues. I want to parse these 2 types of installs: 1) Successful and 2) Failed into 2 tables (Format-Table if I understand correctly) inside a .log file in a folder set up by me.
The part I am having major issues is that I cannot fetch the return codes (ie, did the package install or did it fail to?) that winget throw, and based on that I cannot parse the output into those 2 tables consisting of: AppID, Name (of software), Size (of package), Date (of install or failure to install)
Can someone please help me?
Tried looking for this in the official winget documentation and couldn't find anything. They do mention --verbose, --verbonse-logs and --open-logs but they don't do what I'm trying to achieve here.
If you're using the
wingetCLI you will need to parse the text that the executable puts into the command line output. However, if you use the Microsoft.WinGet.Client PowerShell Module, you can store the result ofInstall-WinGetPackageinto a variable and access theStatusandInstallerErrorCodeproperties or access them directly through the PipelineTo do this in the upgrade flow, you would need to use
Get-WinGetPackageto get the list of packages that are on the machine, filter by the propertyIsUpdateAvailable, pass that through toUpdate-WinGetPackage, and then get the desired properties from the output.This command should do the trick -
Example output -