PowerShell How-To

How To Submit Your First Module to the PowerShell Gallery

Uploading your modules to the gallery will help with distribution headaches and allow for valuable feedback to come your way.

So you've built that great PowerShell module, and it's been saving you tons of time. Awesome! But, you're running into a problem; distribution. You may start by just using the module on your local machine but what if you get a new computer? Maybe it starts to gain popularity between your coworkers and they want to use it too. Now, what? You run into a delivery problem. Don't just put your module up on a file share somewhere. There's a better way: the PowerShell gallery.

The PowerShell Gallery is primarily a public repository of PowerShell modules and scripts. It's a great way to upload modules and scripts to then be available to not only you and your team but also to the community as a whole. Microsoft has released some built-in PowerShell cmdlets available in PowerShell v5, but if you're still on PowerShell v4, you can download the cmdlets separately.

Once you have PowerShell v5 or v4 with the package management module installed, you can get started interacting with the gallery by using the Find-Module. Find-Module. This command is a way you can search the PowerShell Gallery for available modules. Since Find-Module works with different repositories, you'll need to specify the Repository as PSGallery.

Find-Module -Repository PSGallery

This will enumerate all available modules. However, what if you want to contribute a module to the PowerShell Gallery?  To do that you'll use the Publish-Module cmdlet. To use this cmdlet, you'll first need to get your API key. To get that, you'll need to login into the PowerShell Gallery and click on your account. Once there, you'll see your API key. Make note of this.

[Click on image for larger view.] Figure 1.

Once you have the API key, you now have all the pieces of information you need to upload a PowerShell module to the PowerShell Gallery.

To publish a module the gallery, you'll first need to ensure your module is loaded in your current session. For example, I'm going to publish my module called SoftwareInstallManager. I can see that this is available to me now by running Get-Module.

[Click on image for larger view.] Figure 2.

Now that I know it's available, I can use Publish-Module to push it up to the Gallery. I'll do this by providing the module name and the API key that I retrieved earlier.

Publish-Module -Name 'SoftwareInstallManager' -NuGetApiKey  '<MyKey>'

This process will take a little bit, but when it's done, your module should shortly show up on the PowerShell Gallery!

You can now use Find-Module to find the module you just uploaded.

[Click on image for larger view.] Figure 3.

Or, you can also view it on the Web as well.

[Click on image for larger view.] Figure 4.

That's it! Your module is now available for download by the public at large via the PowerShell Gallery. By publishing your module on the gallery allows you to share your hard work with others and get feedback as well. Notice that the author is shown for my module above. This sometimes can lead to further conversations about improving your module or, if you're lucky, a stream of compliments about how great your module is.

About the Author

Adam Bertram is a 20-year veteran of IT. He's an automation engineer, blogger, consultant, freelance writer, Pluralsight course author and content marketing advisor to multiple technology companies. Adam also founded the popular TechSnips e-learning platform. He mainly focuses on DevOps, system management and automation technologies, as well as various cloud platforms mostly in the Microsoft space. He is a Microsoft Cloud and Datacenter Management MVP who absorbs knowledge from the IT field and explains it in an easy-to-understand fashion. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn or follow him on Twitter at @adbertram or the TechSnips Twitter account @techsnips_io.


comments powered by Disqus
Most   Popular