How to publish your PowerShell script to PSGallery

Steps to list your own PowerShell script on the PowerShell Gallery: create an API key, add metadata with New-ScriptFileInfo, run Publish-Script, and fix the common connection error with TLS 1.2 and an updated PowerShellGet.

In this article

Ever created a PowerShell script and wanted to share it? What better place than the PowerShell Gallery itself!

Let’s go through how I listed my own PowerShell script on PSGallery.

Create an API key

API Keys option in the PowerShell Gallery account menu
  • Click Create and set Key Name = script_name and Glob Pattern = *.
Create API key form on the PowerShell Gallery

Add script metadata

  • Now I have my script ready. However, before uploading it, I must add some metadata to it, like Author, Description and Version.
  • For that, I used the New-ScriptFileInfo cmdlet. I set the values as per my needs and ran it in the PowerShell console.
$Parms = @{
  Path = "C:\Scripts\scriptInfo.ps1"
  Version = "2.1.0"
  Author = "Mayank Goyal"
  Description = "This script converts vRO Package directly into JSDoc website by connecting to vRO. Requires nodejs and jsdoc module installed. Create new files *.html & *.js directly from vRO with JSDoc annotation. It consumes a package name which should exist in vRO with all the Actions you want to document and creates .js files with JSDoc Annotations."
  ProjectUri = "https://github.com/imtrinity94/vRODoc"
}
New-ScriptFileInfo @Parms
Get-Content -Path C:\Scripts\scriptInfo.ps1
  • This creates a new file, C:\Users\mayank.goyal1\Downloads\scriptInfo.ps1. Opening it shows this content:

<#PSScriptInfo
.VERSION 2.1.0
.GUID 7202df73-3b8c-4616-adeb-b6d9b97a63c7
.AUTHOR Mayank Goyal
.COMPANYNAME
.COPYRIGHT
.TAGS
.LICENSEURI
.PROJECTURI https://github.com/imtrinity94/vRODoc
.ICONURI
.EXTERNALMODULEDEPENDENCIES 
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
.PRIVATEDATA
#>
<# 
.DESCRIPTION 
 This script converts vRO Package directly into JSDoc website by connecting to vRO. Requires nodejs and jsdoc module installed. Create new files *.html & *.js directly from vRO with JSDoc annotation. It consumes a package name which should exist in vRO with all the Actions you want to document and creates .js files with JSDoc Annotations. 
#> 
  • Copy this file’s content and put it on top of your original script.
Script metadata block added to the top of vRODoc.ps1

Publish the script

  • Now it’s time to publish the script. Use the Publish-Script cmdlet with the file path and the API key you created earlier.
Publish-Script -Path "C:\Scripts\vRODoc.ps1" -NuGetApiKey "<your-api-key>" -Repository PSGallery
  • This should have worked, but it didn’t. I got this error no matter where I ran it from:

Failed to publish script ‘vRODoc’: ‘The underlying connection was closed: An unexpected error occurred on a send.

Fix the connection error

  • The first possible cause is that the system uses TLS 1.1 instead of TLS 1.2. To fix this, run the following command:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

The second possible cause is an outdated PowerShellGet module. To fix this, I ran the following command:

Install-Module PowerShellGet -Force -AllowClobber -Scope CurrentUser
  • Restart the PowerShell terminal and run Publish-Script again. This time it worked.
Publish-Script completing successfully in the PowerShell console

BINGO! It’s published for anyone to use.

vRODoc script listed on the PowerShell Gallery

Download

Update (Nov 2026)

The PowerShell Gallery now requires TLS 1.2, so the connection fix above still applies on older systems. On newer PowerShell versions, you can also publish with Publish-PSResource from the PSResourceGet module, which replaces PowerShellGet.


Discover more from Cloud Blogger

Subscribe to get the latest posts sent to your email.

Enjoyed this post?

Was this helpful?

Leave a Reply