Public/Search-PSModule.ps1
|
function Search-PSModule { <# .SYNOPSIS Searches for modules in the PowerShell Gallery. .DESCRIPTION Searches PSGallery (or another repository) for PowerShell modules. Supports both fuzzy and exact search modes, with configurable sorting. Use -AuthorSearch to search by module author instead of module name. .PARAMETER Query The search term to use. .PARAMETER MaxResults Maximum number of results to return. Default is 50. .PARAMETER ExactSearch If specified, performs an exact name match instead of fuzzy search. .PARAMETER AuthorSearch If specified, searches by author name instead of module name. .PARAMETER SortBy Sort order: Relevance, Downloads, or LastUpdated. .PARAMETER Repository The repository to search. Default is PSGallery. .EXAMPLE Search-PSModule -Query "azure" .EXAMPLE Search-PSModule -Query "Pester" -ExactSearch -SortBy Downloads .EXAMPLE Search-PSModule -Query "Microsoft" -AuthorSearch #> [CmdletBinding()] [OutputType('GalleryModuleInfo[]')] param( [Parameter(Mandatory, Position = 0)] [ValidateNotNullOrEmpty()] [string]$Query, [ValidateRange(1, [int]::MaxValue)] [int]$MaxResults = 50, [switch]$ExactSearch, [switch]$AuthorSearch, [ValidateSet('Relevance', 'Downloads', 'LastUpdated')] [string]$SortBy = 'Relevance', [string]$Repository = 'PSGallery' ) try { $results = Invoke-ProviderSearch -Query $Query -MaxResults $MaxResults -ExactSearch $ExactSearch.IsPresent -AuthorSearch $AuthorSearch.IsPresent -SortBy $SortBy -Repository $Repository return $results } catch { $ErrorActionPreference = 'Continue' Write-Error "Search-PSModule failed: $_" return @() } } |