Skip to content

Instantly share code, notes, and snippets.

@adilio
Last active April 24, 2022 09:04
Show Gist options
  • Save adilio/cdb7e4a78105739fc8520324a3f9767b to your computer and use it in GitHub Desktop.
Save adilio/cdb7e4a78105739fc8520324a3f9767b to your computer and use it in GitHub Desktop.
Run-through of creating a new Cloudsmith repository and pushing PowerShell modules to and from it.
# Create a user account at cloudsmith.io
# Create an Org and Repository at cloudsmith.io
# Build Repository Source URI
$RepoName = 'psdemo'
$User = 'YOUR_USER_NAME_HERE'
$RepoSource = "https://nuget.cloudsmith.io/$User/$RepoName/v2/"
# We needa a PSCredential to upload to repo
$Key = $ENV:CLOUDSMITH_API_KEY
# $Pass = ConvertTo-SecureString $Key -AsPlainText -Force
# $Cred = New-Object 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
Unregister-PSRepository PSGallery
# 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
# Install Modules
$InstallModules= @(
'PSWindowsUpdate',
'Invoke-CommandAs'
)
$InstallModules| Foreach-Object {
Install-Module $_ -Repository $RepoName
}
# Confirm modules were installed
Get-Module -ListAvailable
# Setup Upstream
https://www.powershellgallery.com/api/v2
# Install Modules not in Repo
Install-Module BurntToast -Repository $RepoName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment