How to publish your PowerShell script to PSGallery online

You ever created a PS script and wanted it to share. What best place would it be other than the PowerShell Gallery itself! Let’s go through this article to know how I listed my own PS script on PSGallery. Go to https://www.powershellgallery.com/ and sign in or sign up. Go to API Keys to create a…

By

min read

You ever created a PS script and wanted it to share. What best place would it be other than the PowerShell Gallery itself!

Let’s go through this article to know how I listed my own PS script on PSGallery.

  • Click Create and provide Key Name = script_name and glob pattern = *
  • Now, I have my script ready with me. However, before uploading the script, I must add some metadata to my script like Author, Description, Version etc.
  • For that, I have used New-ScriptFileInfo method. I put the values as per my need and run them inside Powershell console.
$Parms = @{
  Path = "C:\Users\mayank.goyal1\Downloads\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:\Users\mayank.goyal1\Downloads\scriptInfo.ps1
  • This creates a new file C:\Users\mayank.goyal1\Downloads\scriptInfo.ps1. Opening this file show me 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.
  • Now, it’s time to publish our file. Use Publish-Script command along with file path and API key that I have handy already.
Publish-Script -Path "C:\Users\mayank.goyal1\Downloads\vRODoc.ps1" -NuGetApiKey oy2hxalemh46n4ghty*****************************64 -Repository PSGallery
  • This should have worked, but it didn’t. Got this error no matter from where I run it.

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

  • The first problem might be that my system runs TLS11 instead of TLS12, to fix this run the following command:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

The second problem might be that my PowerShellGet Module is not up to date. To fix this I run the following command:

Install-Module PowerShellGet -Force -AllowClobber -Scope CurrentUser
  • Restart PS terminal and run this command again. This time it worked.

BINGO! It’s published for anyone to use.

Related Posts

Leave a Reply

%d bloggers like this: