Skip to content

Instantly share code, notes, and snippets.

@adilio
Last active June 24, 2022 22:56
Show Gist options
  • Save adilio/b060e8c289489ab5665b630e656c5ea2 to your computer and use it in GitHub Desktop.
Save adilio/b060e8c289489ab5665b630e656c5ea2 to your computer and use it in GitHub Desktop.
Walk through of setting up a PowerShell Repo in Cloudsmith
# Create a user account at cloudsmith.io
# Create an Org and Repository at cloudsmith.io
# In your PowerShell console,
# check that PSGallery repo is present only
Get-PSRepository
# Build Repository Source URI
$RepoName = 'YOUR-REPO-NAME'
$OrgName = 'YOUR-ORG'
$RepoSource = "https://nuget.cloudsmith.io/$OrgName/$RepoName/v2/"
# We needa a PSCredential to communicate with to repo
$Key = 'YOUR-API-KEY'
$Pass = ConvertTo-SecureString $Key -AsPlainText -Force
$Cred = New-Object -TypeName PSCredential('token',$Pass)
#Save modules locally
Set-Location '~/Documents/ps'
$SaveModules= @(
'PSWindowsUpdate',
'Invoke-CommandAs'
)
$SaveModules| Foreach-Object {
Save-Module $_ -Path .
}
# To aviod confusion, we will reomve PSGallery for now
# You don't have to remove this, but there are also
# commands at the bottom to reset this to defaults
Unregister-PSRepository PSGallery
Get-PSRepository
# Register the package source and repo locally
$SourceParams = @{
Name = $RepoName
Credential = $Cred
Location = $RepoSource
Trusted = $true
ProviderName = 'Nuget'
}
Register-PackageSource @SourceParams
$RepoParams = @{
Name = $RepoName
Credential = $Cred
SourceLocation = $RepoSource
PublishLocation = $RepoSource
InstallationPolicy = 'Trusted'
}
Register-PSRepository @RepoParams
# Push modules up to repo
(Get-ChildItem -Exclude 'scripts').FullName | ForEach-Object {
Publish-Module -Path $_ -Repository $RepoName -NugetApiKey $Key
}
# Confirm modules in repo
Find-Module -Repository $RepoName -Credential $Cred
# Install Modules
$InstallModules= @(
'PSWindowsUpdate',
'Invoke-CommandAs'
)
$InstallModules| Foreach-Object {
Install-Module $_ -Repository $RepoName -Credential $Cred
}
# Confirm modules were installed
Get-Module -ListAvailable
# Setup Upstream
https://www.powershellgallery.com/api/v2
# Install Modules not in Repo
Find-Module BurntToast -Repository $RepoName -Credential $Cred | Install-Module
# Cleanup tasks
<#
Unregister-PSRepository psdemo
Unregister-PackageSource psdemo
Register-PSRepository -Default
Get-PSRepository
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment