powershellwinget

Return the current version of an app with winget


I'm trying to figure out how I can grab the current version of an app installed on a computer using Winget, and save it to a variable.

Eg. if I enter:

winget list --name 7-Zip

This returns:

Name              Id        Version Source
-------------------------------------------
7-Zip 24.09 (x64) 7zip.7zip 24.09   winget

So I want to grab only the "24.09" part of this output. Unfortunately my knowledge of PowerShell scripting isn't quite advanced enough to do this.

My goal is to create a remediation script for Intune where I can output something like this at the end:

Write-Output "The current installed version of $appName is $appVersion"

Solution

  • To provide an object-based alternative to Theo's helpful text parsing-based answer: