PowerShell Modules are an important resource for scripting, and the ability to share PowerShell modules is easy with online repositories like the PowerShell Gallery. The ability to publish PowerShell modules is available in PowerShell ModuleManager v1.1.1 and later. You’re welcome!
The Publish-Module command—from the PowerShellGet module—allows you to share modules from your local computer to online or local galleries.
To run the Publish-Module command, you can either specify the name or the path of the folder containing the module. If publishing by name, the first module found in the paths of the PSModulePath environment variable ($env:PSModulePath) will be published—so it is important to specify a minimum version if you have multiple versions.
When publishing modules to a NuGet-based online repository like the PowerShell Gallery, an API key is required. To get an API key for the PowerShell Gallery, you will need to create an account on the PowerShell Gallery and generate a new key for this module package. Local repositories do not need a key.
By default, Windows 10 ships with an old version of PowerShellGet, which provides the Publish-Module command, so this module must be updated to recognize the API key from the latest gallery site.
Publishing a module requires metadata, most of which is taken from the module manifest (.psd1). The minimum required data is:
There should be no output if the Publish-Module command runs successfully.
To use the new Publish Module feature in PowerShell ModuleManager, first select the module you want to publish from the list of modules:
Then click the Publish Module button on the ribbon (Home->Repository):
This will open the Publish dialog:
Select the registered repository in the Publish to field, specify the NuGetAPI Key if you are publishing to an online repository like the PowerShell Gallery, then select the Version of the module. This is the minimum information needed to publish your module.
Optional information that can be specified when publishing:
If this information already exists in the module manifest, you do not need to enter it in the Publish dialog. Specifying this information will not automatically update the local module’s manifest. To update the local module manifest without opening and editing the psd1 file, you must check the Update the module manifest (.psd1) file checkbox:
After filling in the dialog, select Publish to publish the module.
Any repository you are attempting to publish to must be a registered repository in PowerShell. Repositories can be added or edited by selecting Registered Repositories on the ribbon (Home->Repository):
When registering a repository, specify where modules should be published by entering the repository URL or file path in the Publish Location field:
Note: The default registered repository is the PowerShell Gallery (PSGallery).
A .nupkg file is created when a module is published to a registered repository, which allows you to find the published module when performing a search.
To search within repositories, open Repository Search (Home->Repository):
If you write a PowerShell module, chances are you’ll want to publish it. Creating excellent PowerShell modules is one thing, but sharing them with others takes them to a whole new level! We hope you find this new PowerShell ModuleManager feature useful.
You will need PowerShell ModuleManager 2019 v1.1.1 or later to use the publish functionality. You can view the complete service build log here.