PowerShell modules are packages of scripts, functions, and other resources that can be used to extend the functionality of PowerShell. Modules can be created by anyone and shared with the community, or they can be provided by software vendors as part of their products. In this article, we’ll look at how to find, install, and use modules in PowerShell.

Finding Modules

PowerShell modules can be found on the PowerShell Gallery, a repository of over 8,000 modules contributed by the community. To find a module on the gallery, you can use the Find-Module cmdlet. You could also browse around their website, but usually you’re looking for the modules while you’re using PowerShell, and it’s really handy to search for the modules you’re looking for right from the terminal or VS Code. For example, to search for a module that contains the term “azure”, you can use the following command:

Find-Module -Name *bird*

This will return a list of modules whose names or descriptions contain the word “bird”. You can then select the module you want to install based on the name and description.

Installing Modules

Once you have found a module that you want to use, you can install it using the Install-Module cmdlet. For example, to install the BlueBirdPS module, which can be used to interact with Twitter directly from PowerShell, you can use the following command:

Install-Module -Name BlueBirdPS

This will download and install the BlueBirdPS module from the PowerShell Gallery. If the module has dependencies that are not installed, the Install-Module cmdlet will also download and install those dependencies.

Updating Modules

Modules can be updated using the Update-Module cmdlet. For example, to update the BlueBirdPS module to the latest version, you can use the following command:

Update-Module -Name BlueBirdPS

This will check for a newer version of the module on the PowerShell Gallery and download and install it if one is found.

Using Modules

Once a module is installed, you can use its commands and functions by importing the module using the Import-Module cmdlet. For example, to import the BlueBirdPS module, you can use the following command:

Import-Module -Name BlueBirdPS

It’s worth noting that if you try to run a command from a module that is installed, but not loaded – most of the time you won’t get an error. Instead, PowerShell takes care of that for you, sees that you have a command available in an installed module and loads the module for you on-demand. That’s nice!

But sometimes you need to make sure that you’ve got the latest version of a module installed (or maybe you’re writing one yourself, and you want to update the version). In that case, just use the -Force parameter to overwrite the currently loaded module with the updated version.

Import-Module -Name BlueBirdPS -Force

This will make the commands and functions in the BlueBirdPS module available in your PowerShell session. You can then use them just like any other PowerShell cmdlet.

Finding Commands in a Module

Once you have imported a module, you may want to know which commands are available in it. You can do this using the Get-Command cmdlet with the -Module parameter.

For example, to find all the commands in the Az module, run the following command:

Get-Command -Module BlueBirdPS

This will display a list of all the commands available in the BlueBirdPS module. You can also use wildcard characters to filter the list of commands. For example, to find all the commands in the BlueBirdPS module that contain the word “storage”, run the following command:

Get-Command -Module BlueBirdPS *storage*

This will display a list of all the commands in the BlueBirdPS module that contain the word “tweet” in their names or descriptions. You can then use these commands to perform various operations related to posting and searching for tweets.

Listing Available Modules

To see which modules are available on your system, you can use the Get-Module cmdlet with the -ListAvailable parameter. This will return a list of all the modules that are installed on your system and available for use.

Get-Module -ListAvailable

Conclusion

PowerShell modules are a powerful way to extend the functionality of PowerShell. By using modules created by the community or by software vendors, you can save time and effort by leveraging code that has already been written and tested. By using the Find-Module, Install-Module, and Update-Module cmdlets, you can easily find and install modules from the PowerShell Gallery. Once installed, you can use modules in your PowerShell scripts and interactive sessions by importing them with the Import-Module cmdlet.