Home » Find Modules in PowerShell

Find Modules in PowerShell

The Find-Module cmdlet finds modules in a repository that match the specified criteria. It returns a PSRepositoryInfo object for each module it finds.

If no parameter is used that limit the version, Find-Module returns the latest version of the module.

To get a list of module versions in PowerShell, use the AllVersion parameter.

PowerShell Get Module Versions
PowerShell Get Module Versions

In this article, we will discuss how to use the Find-Module cmdlet to find a module by name, get the PowerShell module by minimum version and Find a module by specific version.

How to Find Module by Name

Use the Find-Module cmdlet to find a module by name in the default repository.

The Find-Module uses the Name parameter to specify the PowerShellGet module and returns its information.

Find-Module -Name PowerShellGet

The output of the above PowerShell script finds a module in the repository and displays the module version, name, repository name, and description.

PS C:\> Find-Module -Name PowerShellGet                                                                                 
Version    Name                                Repository           Description
-------          ----                                            ----------                  -----------
2.2.5      PowerShellGet                    PSGallery            PowerShell module with commands for discovering,...


PS C:\>    

Find Modules with Similar Names

Use the Find-Module to find modules in the repository. If you want to find modules starting with a name, use an asterisk (*) wildcard with the module name.

Find-Module -Name xSQL* 

In the above PowerShell script, the Find-Module cmdlet finds modules that contain the xSQL name in it.

The output of the above PowerShell script is:

PS C:\> Find-Module -Name xSQL*                                                                                         
Version      Name                      Repository         Description
-------           ----                               ----------               -----------
1.0              xSql                            PSGallery            The xSqlPs module is part of the Windows PowerSh...
9.1.0.0       xSQLServer               PSGallery            Module with DSC Resources for deployment and con...
1.4.0.0       xSqlPs                        PSGallery            SQL module.


PS C:\>    

How to Find module by minimum version

Find-Module cmdlet uses the MinimumVersion parameter to search for a module’s minimum version. However, if the repository contains a newer version of the module, it returns the latest version.

Find-Module -Name PowerShellHumanizer -MinimumVersion 1.6 

In the above PowerShell script, the Find-Module cmdlet uses the Name parameter to specify the module name PowerShellHumanizer and the MinimumVersion parameter to specify version 1.6

However, the repository contains the newer version of the module, hence the newer version is returned.

PS C:\> Find-Module -Name PowerShellHumanizer -MinimumVersion 1.6                                                       
Version    Name                                Repository     Description
-------        ----                                       ----------            -----------
3.2          PowerShellHumanizer    PSGallery         PowerShell Humanizer wraps Humanizer: meets all ...


PS C:\>                                                                         

Find a Module by Specific Version

The Find-Module cmdlet has a RequiredVersion parameter to search for a specific version in the repository. If the required version matches, it returns the results else an error is returned.

Find-Module -Name PowerShellHumanizer -RequiredVersion 1.2 

In the above PowerShell script, the Find-Module cmdlet uses the Name parameter to specify the module name PowerShellHumanizer. It uses the parameter RequiredVersion to specify version 1.2.

The above script finds the module by its version and gets module information as follows

PS C:\> Find-Module -Name PowerShellHumanizer -RequiredVersion 1.2                                                      
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
1.2        PowerShellHumanizer                 PSGallery            PowerShell Humanizer wraps Humanizer: meets all ...

However, if we specify the version which is not available, Find-Module returns an error as below

Find-Module -Name PowerShellHumanizer -RequiredVersion 1.2.4                  
PS C:\> Find-Module -Name PowerShellHumanizer -RequiredVersion 1.2.4                                                    PackageManagement\Find-Package : No match was found for the specified search criteria and module name
'PowerShellHumanizer'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1397 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

Find a Module in Specified Repository

Use the Find-Module cmdlet with the Repository parameter to search for a module in the specific repository.

PS C:\> Find-Module -Name PowerShellHumanizer  -Repository PSGallery   

The output of the above PowerShell script gets the module version, name, and repository name as follows

PS C:\> Find-Module -Name PowerShellHumanizer  -Repository PSGallery                                                    
Version    Name                                Repository           Description
-------    ----                                ----------           -----------
3.2        PowerShellHumanizer                 PSGallery            PowerShell Humanizer wraps Humanizer: meets all ...


PS C:\>                                                                                                                              

Conclusion

I hope the above article on how to use the Find-Module cmdlet to get the module version and find a module in the specified repository is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.