PowerShell Pipeline

Exploring the PowerShell Gallery

Grabbing and organizing cmdlets has been made much easier in PowerShell V5.

Ever have the need to get a PowerShell module but hated having to search for it online on a variety of sites and then having to download the module to throw it into your Modules folder? Ok, it may not be that bad of a thing, but that the process of getting a module installed is about to change. Starting with PowerShell V5, we now have a new module called PowerShellGet which comes with 11 cmdlets that you can use to explore, download, install and even publish your own modules to the gallery.

[Click on image for larger view.]  Figure 1. List of cmdlets in PowerShellGet module.

You can go to the PowerShell Gallery Web site and view all of the available modules, but if you click on one you will not have the option to download the module. Instead you are shown the command needed to install the module from PowerShell using Install-Module. Also listed is the command to save the module so you can be sure that it doesn't do anything malicious as well using Save-Module.

[Click on image for larger view.]  Figure 2 PowerShellGallery Web site.

Starting from the top, we should search for a module and then download it so we can be sure that it meets our needs and doesn't potentially have code that would be considered malicious before we move ahead and install it. Note that if you just type Find-Module and hit return, you will be flooded with all of the modules that reside on the gallery. There are quite a few ways to filter for results with this cmdlet.

[Click on image for larger view.]  Figure 3. Syntax for Find-Module.

I am going to use the –Name parameter and filter for a module that sounds good to me. I'm not too concerned about a specific version or tags and I am not interested in a DSCResource at this time.

Find-Module -Name Posh* | Out-GridView -PassThru
[Click on image for larger view.]  Figure 4. Selecting a module via Out-GridView.

Notice how I piped the output of the results into a gridview UI using Out-GridView. Using the –PassThru parameter means that if I select something and click OK, it will present the object at the end that could then be piped into another command, such as Save/Install-Module to receive the module. If there are a lot of items returned, I can easily use the Filter text box to quickly locate what I need. In this case, I am going to download my own module, PoshRSJob and check it out.

Find-Module -Name Posh* | Out-GridView -PassThru  | 
Save-Module -Path C:\temp -Verbose
[Click on image for larger view.]  Figure 5. Confirmation to download and install a module.

Because I do not actually trust this location, I am prompted with this asking if I want to go ahead with the downloading of this module. I'll say yes and continue on with the download.

[Click on image for larger view.]  Figure 6. Downloading a module to view.

Perfect! Now I can go in and make sure nothing looks out of the ordinary. Of course, I could simply copy the folder and its items to my modules directory, but instead I will go ahead and run Install-Module instead to download the files and place them in the appropriate location. Because I want to show off another cmdlet soon, I am actually going to install an older version of the module.

Find-Module poshrsjob  -AllVersions |  Out-GridView -PassThru  | 
Install-Module -Verbose
[Click on image for larger view.]  Figure 7. Picking a module to install.

One version back should be good enough this time around.

[Click on image for larger view.]  Figure 8. Install a module from the gallery.

And now I have a module to use without having to download from a website and manually placing the files in my modules folder. If I wanted to verify this I can run Get-Module –ListAvailable –Name PoshRSJob to see that the module is in fact available and is the proper version that I chose to install.

To see all of the installed modules from the gallery, I can use Get-InstalledModule.

Get-InstalledModule 
[Click on image for larger view.]  Figure 9. Viewing modules installed from the gallery.

This is useful to know what modules came from the PowerShellGallery (or another internal gallery). We are also able to see the version and description of the modules that were downloaded and installed.

If I am done with a module and no longer need in installed, I can just use Uninstall-Module to completely remove it from my system.

Uninstall-Module -Name Reflection  -Verbose 

Maybe I want to check to see if a module needs to be updated. I can use Update-Module to check and update a module if the version is higher than what is already installed on my system.

Update-Module -Name PoshRSJob -Verbose
[Click on image for larger view.]  Figure 10. Updating an existing module.

Now I have the latest update to my module! If I already have the latest module version, then nothing happens at all.

[Click on image for larger view.]  Figure 11. No need to update a module if it is already up to date.

No big deal at all, right? Just a simple check and no need to re-download the module since the version is already up to date or higher than what is available on the gallery.

One last thing in this article: you noticed how I didn't trust the repository as I was prompted for confirmation before downloading the module? You can change this by updating the InstallationPolicy for a particular repository. In this case, we only have one repository as show when we use Get-PSRepository.

Get-PSRepository
>
[Click on image for larger view.]  Figure 12. Checking the trust of a repository.

We can change this using Set-PSRepository and setting the InstallationPolicy to Trusted.

Set-PSRepository -Name PSGallery  -InstallationPolicy Trusted  -Verbose 
[Click on image for larger view.]  Figure 13. etting the trust of a repository.

Now you can download/install modules without the confirmation prompt. Keep in mind that this shouldn't be used against repositories that you do not trust as it provides a little more time to hold off on installation a potentially bad module.

There are still some other cool things with the PowerShellGet module such as publishing your own module and adding another PSRepository but that is a topic for another article. Now you can go forward and explore the gallery check out some of the cool modules that the community has published!

About the Author

Boe Prox is a Microsoft MVP in Windows PowerShell and a Senior Windows System Administrator. He has worked in the IT field since 2003, and he supports a variety of different platforms. He is a contributing author in PowerShell Deep Dives with chapters about WSUS and TCP communication. He is a moderator on the Hey, Scripting Guy! forum, and he has been a judge for the Scripting Games. He has presented talks on the topics of WSUS and PowerShell as well as runspaces to PowerShell user groups. He is an Honorary Scripting Guy, and he has submitted a number of posts as a to Microsoft's Hey, Scripting Guy! He also has a number of open source projects available on Codeplex and GitHub. His personal blog is at http://learn-powershell.net.

comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.