Find-Module, Find-Script – Don’t Recreate the Wheel

The PowerShell Gallery is a collection of modules and scripts that is community driven to help us automate everyday tasks. Sometimes, we have an idea that could written into a function or script, however, most of the time, someone else had the same idea and published their work to the PowerShell Gallery. There is no need to recreate the wheel and re-write it, use the community to our advantage. We’ll take a look at multiple Cmdlets, Find-Module, Find-Script, Install-Module, and Install-Script, and find out what each of them provide.

Find-Module and Install-Module

Find-Module allows us the browse the PowerShell Gallery and find if there is a module in the community that has been created. Running Get-Help Find-Module, we can see there are multiple parameters to use to help narrow our search. For demonstration, we will find the Azure PowerShell (Az) module by Microsoft using the Find-Module Cmdlet.

Great. We were able to find the Az module and returned some information about the module: Version, Name, Repository, and Description. But what if we did not know the name of a module we are looking for? The -Name parameter accepts wildcards for partial searches, we can enter in Find-Module -Name Az* and will return any module in the gallery that starts with “Az”. We can also search for DSC Resources using the Find-Module Cmdlet using the -Includes DscResource parameter. This will only return DSC Resources available in the PowerShell Gallery

Once we found the module that we want to use, we can install the module using the Install-Module Cmdlet. This will install the community module in our default module install directory: C:\Program Files\WindowsPowerShell\Modules or if using PowerShell Core: C:\Program Files\PowerShell\Modules. Lets take the example above and use it to install the Az Module.

We can take the Find-Module Cmdlet and pipe it to the Install-Module Cmdlet to install the module. But, we also have the ability to install a specific version of a module using the -RequiredVersion parameter.

Not using the -RequiredVersion parameter will install the latest version of the module.

Note: Find-Module and Install-Module was introduced in PowerShell version 5.0.

Find-Script and Install-Script

Find-Script works the same way as Find-Module, however, instead of finding modules, we are now finding scripts. Find-Script will return .ps1 scripts in the PowerShell Gallery that could be installed. Lets take a look at an example to find a script and than later on we will install it. The same rules apply when trying to find a script, we can use wildcards in our search to find a certain script.

We searched for all scripts that start with Get-*, now lets find the script we want to install: Join-String

Now that we found the scripts, lets install it using the same pipeline. Using the Install-Script Cmdlet, the script will install in the default script location: C:\Program Files\WindowsPowerShell\Scripts or if using PowerShell Core: C:\Program Files\PowerShell\Scripts.

We can still use the -RequiredVersion parameter if a specified version is required, but using the command above will install the latest.

Find-Module, Find-Script, Install-Module, and Install-Script are great to find and install modules or scripts from the PowerShell Gallery, there is no need to recreate the wheel, (Most of the time). You can also search the PowerShell Gallery by visiting the website here. When searching for a module or script, the site will show you the command to run in PowerShell to install the module or script.

Just a reminder that these Cmdlets were introduced in PowerShell version 5.0 and are in the PowerShellGet module. The links below are Microsoft’s documentation for each Cmdlet with examples and other parameters that can be used.



About pwshliquori

Hi, I’m Chris. I am not a programmer or developer, I am a scripter that enjoys PowerShell and a glass of bourbon. 5 years deep into PowerShell, my primary focus is to automate pretty much anything I don’t like to do manually. Follow me on twitter - @pwshliquori

One thought on “Find-Module, Find-Script – Don’t Recreate the Wheel

Comments are closed.