So you've created that excellent script. Now what? Publish that PowerShell script to the PowerShell Gallery! The PowerShell Gallery is a great place to share both PowerShell modules and scripts.

The Gallery is typically known for just publishing modules, but you can publish scripts as well. To publish anything to the PowerShell Gallery, you'll first need to set up an account and get your API key. Once you've set up your account, you should be ready to go!

To proceed, you'll need to know your API key. The Publish-Script command requires it. You'll find that API key by visiting your profile in the PowerShell Gallery.

PowerShell Gallery API Key

PowerShell Gallery API Key

I'm now going to assume you've got your API key available and you've got at least PowerShell v5 with the PowerShellGet module installed. With those assumptions out of the way, let's now prepare a script for publishing.

I've got a sample script at C:\test.ps1 that looks like this:

The Publish-Script command requires two parameters: the script you'll be publishing and the API key that gives you access to your account. But as we try to publish the script as is, things don't work quite right.

This doesn't work because the PowerShell Gallery requires some specific information at the top of every script published there. We can use the Update-ScriptFileInfo command to add this information to existing scripts or use the New-ScriptFileInfo command to create a blank script with the required information. To prevent the possibility of overwriting our previous script, I'll create a new script with New-ScriptFileInfo, add this information to it, and then copy and paste my existing script to this one.

Now that I have created my new script with the correct comments added, I'll try to publish the script again using the same command.

You'll see this time you'll receive no error! You can also confirm the script was published by using the Find-Script command and specifying the name of the original script.

After the script is published, you can also see it under your Manage My Items section directly on the PowerShell Gallery site.

PowerShell Gallery Managing Items

PowerShell Gallery Managing Items

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!


Users who have LIKED this post:

  • avatar

Leave a reply

Your email address will not be published. Required fields are marked *


© 4sysops 2006 - 2020


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account