Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 = "$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