How To Upload a Module to the PowerShell Gallery
Got a module that you're especially proud of? Share it with others.
- By Adam Bertram
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 if you'd like to use these cmdlets down-level.
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 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.
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 to 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.
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.
Or, you can also view it on the Web as well.
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.
Adam Bertram is an independent consultant, technical writer, trainer and presenter. Adam specializes in consulting and evangelizing all things IT automation mainly focused around Windows PowerShell. Adam is a Microsoft Windows PowerShell MVP, 2015 powershell.org PowerShell hero and has numerous Microsoft IT pro certifications. He is a writer, trainer and presenter and authors IT pro course content for Pluralsight. He is also a regular contributor to numerous print and online publications and presents at various user groups and conferences. You can find Adam at adamtheautomator.com or on Twitter at @adbertram.