PowerShell Gallery upstream source
Enabling upstream sources for your feed extends your developers' access to packages from public registries. In this article, you'll learn how to set up the PowerShell Gallery as an upstream source and consume PowerShell packages from the public registry.
Prerequisites
- NuGet.exe
- Azure Artifacts Credential Provider
- An Azure DevOps organization and a project. Create an organization or a project if you haven't already.
- An Azure Artifacts feed. Create a new feed if you don't have one already.
Add PowerShell Gallery upstream source
If the PowerShell Gallery upstream source is not available in your feed by default, you can add it as follows:
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Artifacts, and then select your feed from the dropdown menu.
Select the gear icon button to navigate to your Feed Settings.
Select Upstream Sources, and then select Add Upstream.
Select Public source, and then select PowerShell Gallery from the dropdown menu. Select Add when you're done.
Select Save in the upper right corner to save your changes. Select Save again if prompted to confirm your choices.
Connect to feed
Create a personal access token with Packaging > Read & write permissions.
Run the following commands in a PowerShell prompt window, replacing the placeholders with the appropriate information:
$patToken = "<YOUR_PERSONAL_ACCESS_TOKEN>" | ConvertTo-SecureString -AsPlainText -Force
$myCredentialsObject = New-Object System.Management.Automation.PSCredential("<USER_NAME>", $patToken)
Run the following command to register your feed as a PSRepository. Replace the placeholders with the appropriate values:
Project-scoped feed:
Register-PSRepository -Name "PSGalleryUpstream" -SourceLocation "https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v2" -InstallationPolicy Trusted -Credential $myCredentialsObject
Org-scoped feed:
Register-PSRepository -Name "PSGalleryUpstream" -SourceLocation "https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v2" -InstallationPolicy Trusted -Credential $myCredentialsObject
Save packages from upstream
Now that you added the PowerShell Gallery as an upstream source and registered your feed as a PSRepository, every time you install a package from upstream, a copy will be saved to your feed. In the following example, we'll install the PSScriptAnalyzer module:
Install-Module -Name PSScriptAnalyzer -Repository PSGalleryUpstream
Note
To save packages from upstreams, you must have the Feed and Upstream Reader (Collaborator) role or higher. See Manage Permissions for more details.
View saved packages
You can access the packages you've saved from the PowerShell Gallery by choosing the appropriate Source from the dropdown menu.
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Artifacts, and then select your feed from the dropdown menu.
Select Source on the right, and then select PowerShell Gallery to filter for packages saved from upstream. You can see that the PSScriptAnalyzer package, which we installed in the previous step, has been saved to our feed.