Publishing your PowerShell modules to the PowerShell Gallery (PSGallery) is an excellent way to share your work with the community. Initially, I encountered issues when publishing because I was using PowerShell 5. Since these problems cost me quite some time, I decided to write this guide to help you avoid similar pitfalls. Make sure you’re running PowerShell 7.x or newer, and follow this straightforward guide to successfully publish your own modules.
I personally use the ISESteroids module, developed by Dr. Tobias Weltner, to create my modules, which significantly simplifies the process for me. You can try it out for a few days before purchasing a license, and more information is available at powershell.one.
Prerequisites
Ensure you have the following:
- PowerShell 7.x or newer
- NuGet Provider (Install via
Install-PackageProvider -Name NuGet -Force
) - An account on the PowerShell Gallery
- An API key from your PowerShell Gallery Account
Step-by-Step Guide
Step 1: Create a Module Manifest
Start by creating a manifest file (.psd1
). This file contains essential information about your module:
New-ModuleManifest -Path '.\MyModule\MyModule.psd1' -RootModule 'MyModule.psm1' -Author 'YourName' -Description 'Description of your module' -PowerShellVersion '5.1'
Make sure to properly specify:
ModuleVersion
Tags
ProjectUri
LicenseUri
Step 2: Test Your Module
Always test your module thoroughly before publishing:
Import-Module .\MyModule
Get-Command -Module MyModule
Test-ModuleManifest -Path '.\MyModule\MyModule.psd1'
Step 3: Publish Your Module
Publish using the following command:
Publish-Module -Path '.\MyModule' -NuGetApiKey 'YourAPIKey'
My Published Modules
I’ve published several modules to the PowerShell Gallery:
- BlizzWoWRetailProfile (Latest Version: 3.2.1)
Access character profiles including achievements, reputations, and PvP stats from World of Warcraft. - BlizzWoWRetailGameData (Latest Version: 3.5.1)
Provides interaction with Blizzard’s World of Warcraft Game Data API. - BlizzMySQLHelper (Latest Version: 1.7.1)
Helper functions for integrating Blizzard API data with MySQL.
Publishing these modules has taught me that the process is straightforward and highly rewarding. It’s fantastic to see your modules used and appreciated by others in the community.
Happy publishing!