This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Find-Module.
When to use Find-Module
The Find-Module cmdlet finds modules in a repository that match the specified criteria.
Find-Module returns a PSRepositoryItemInfo object for each module it finds. The objects can be sent down the pipeline to cmdlets such as Install-Module.
The first time Find-Module attempts to use a repository, you might be prompted to install updates. If the repository source is not registered with Register-PSRepository cmdlet, an error is returned.
Find-Module returns the newest version of a module if no parameters are used that limit the version.
To get a repository’s list of a module’s versions, use the parameter –AllVersions.
How to use Find-Module
Find a module by name:
Find-Module -Name PowerShellGet
The Find-Module cmdlet uses the –Name parameter to specify the PowerShellGet module.
Find a module by minimum version:
Find-Module -Name PowerShellGet -MinimumVersion 1.6.5
The Find-Module cmdlet uses the -Name parameter to specify the PowerShellGet module.
The -MinimumVersion parameter specifies version 1.6.5.
Find-Module returns PowerShellGet version 2.2.1 because it exceeds the minimum version and is the most current version.
Find a module in a specific repository:
Find-Module -Name PowerShellGet -Repository PSGallery
The Find-Module cmdlet uses the –Name parameter to specify the PowerShellGet module. The –Repository parameter specifies to search the PSGallery repository.
Find a module that contains a DSC resource:
Find-Module -Repository PSGallery -Includes DscResource
The Find-Module cmdlet uses the –Repository parameter to search the repository, PSGallery.
The –Includes parameter specifies DscResource, which is a functionality that the parameter can search for in the repository.
Learn last week’s command: Find-DscResource.
Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.