PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
490 stars 94 forks source link

Find-PSResource with multiple tags not working as expected #1492

Closed jdhitsolutions closed 9 months ago

jdhitsolutions commented 10 months ago

Prerequisites

Steps to reproduce

I can run these commands to search for resources by tag.

Find-PSResource -Tag yml -type module
Find-PSResource -Tag json-type module

The -Tag parameter will accept an array, so it is reasonable to assume I can run:

Find-PSResource -Tag yml,json -type module

Expected behavior

I would expect to see the results from the two separate commands.

Actual behavior

I get the error: Package with Tags 'yml, json' could not be found in any registered repositories

The parameter will work only when all tags are in the same module.

PS C:\> Find-PSResource -Tag demo,teaching -Type module

Name            Version Prerelease Repository Description
----            ------- ---------- ---------- -----------
PSTeachingTools 4.2.0              PSGallery  A set of commands and tools for teaching PowerShell.

Error details

Exception             : 
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package with Tags 'yml, json' could not be found in any registered repositories.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.FindHelper
CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel….Cmdlets.FindHelper:FindHelper) [Find-PSResource], ResourceNotFoundException
FullyQualifiedErrorId : PackageWithTagsNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
InvocationInfo        : 
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 26
    Line             : Find-PSResource -Tag yml,json -type module
    Statement        : Find-PSResource -Tag yml,json -type module
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -Tag yml,json -type module
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

PS C:\> Get-module Microsoft.PowerShell.PSResourceGet;$PSVersionTable | format-Table

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.0.0                 Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-P…

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Same behavior in Windows PowerShell.

Visuals

No response

mklement0 commented 10 months ago

Indeed, it looks like Find-Module's OR logic with respect to multiple tags mistakenly became AND logic in Find-PSResource.

anamnavi commented 9 months ago

@jdhitsolutions thanks for creating this issue! We intentionally changed our -Tag logic to reflect AND logic with Find-PSResource instead of OR, so that the search is less computationally expensive and the search result is narrower. If a user wishes to see packages with tag1 OR tag2 they would need to provide 2 separate commands.

Good catch that the docs do not yet reflect this, we will update this on our end, thanks!

anamnavi commented 9 months ago

@jdhitsolutions in the docs for Find-PSResource for the -Tag parameter it states, "If multiple tags are specified, the cmdlet only returns resources that include all the tags provided." Just wanted to point to that, but please feel free to re-open if you feel we should add more clarity thanks :)