Skip to content

Commit

Permalink
Installed package wildcard search
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbergstrom committed Dec 4, 2021
1 parent 9266d09 commit bd84e99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

## 0.0.3 - 2021-12-04 - Installed Package Wildcard Search Support
### Added
* Installed packages can now be searched with wildcards, aligning with standard PowerShell behavior

## 0.0.2 - 2021-12-04 - WinGet v1.x support and PowerShell Crescendo
### Added
* Support for WinGet v1.x, which brings several new features
Expand Down
2 changes: 1 addition & 1 deletion src/WinGet.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
RootModule = 'WinGet.psm1'
ModuleVersion = '0.0.2'
ModuleVersion = '0.0.3'
GUID = '468ef37a-2557-4c10-92ec-783ec1e41639'
Author = 'Ethan Bergstrom'
Copyright = ''
Expand Down
16 changes: 4 additions & 12 deletions src/public/Get-InstalledPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@ function Get-InstalledPackage {
$RequiredVersion = $(Find-WinGetPackage -Name $Name).Version
}

$WinGetParams = @{
}

# If a user provides a name without a wildcard, include it in the search
# This provides wildcard search behavior for locally installed packages, which WinGet lacks
if ($Name) {
$WinGetParams.Add('ID',$Name)
$WinGetParams.Add('Exact',$true)
}

# Convert the PSCustomObject output from Cobalt into PackageManagement SWIDs, then filter results by version requirements
Cobalt\Get-WinGetPackage @WinGetParams | ConvertTo-SoftwareIdentity |
Where-Object {Test-PackageVersion -Package $_ -RequiredVersion $RequiredVersion -MinimumVersion $MinimumVersion -MaximumVersion $MaximumVersion}
# This provides wildcard search behavior for locally installed packages, which WinGet lacks
Cobalt\Get-WinGetPackage | ConvertTo-SoftwareIdentity |
Where-Object {-Not $Name -Or ($_.Name -Like $Name)}
Where-Object {Test-PackageVersion -Package $_ -RequiredVersion $RequiredVersion -MinimumVersion $MinimumVersion -MaximumVersion $MaximumVersion}
}

0 comments on commit bd84e99

Please sign in to comment.