Skip to content

Instantly share code, notes, and snippets.

@guneysus
Forked from Badgerati/GitHub_PSModule.ps1
Created March 6, 2022 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guneysus/7a7334bd23ff298b607978ab9f106608 to your computer and use it in GitHub Desktop.
Save guneysus/7a7334bd23ff298b607978ab9f106608 to your computer and use it in GitHub Desktop.
Example script for publishing a PowerShell module to the NuGet GitHub Package Registry
<# --
Register the GitHub Package Registry
-- #>
$username = '<github-username>'
$token = '<github-personal-token>'
$sourceName = 'GitHub'
$source = "https://nuget.pkg.github.com/$username/index.json"
# add the github package registry as a nuget source
nuget sources Add -Name $sourceName -Source $source -UserName $username -Password $token
# register the github package registry as a powershell repository
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $token -Force)
Register-PSRepository -Name $sourceName -SourceLocation $source -PublishLocation $source -Credential $creds
<# --
Publish PowerShell module
-- #>
$module = '<module-name>'
$version = '<module-version>'
$apiKey = 'n/a' # keep this as n/a!
Publish-Module -Name $module -Repository $sourceName -RequiredVersion $version -Credential $creds -Force -NuGetApiKey $apiKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment