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

If the PowerShell Gallery upstream source is not available in your feed by default, you can add it as follows:

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select the gear icon button gear icon to navigate to your Feed Settings.

  4. Select Upstream Sources, and then select Add Upstream.

    A screenshot showing how to add a new upstream source.

  5. Select Public source, and then select PowerShell Gallery from the dropdown menu. Select Add when you're done.

    A screenshot showing how to add the PowerShell Gallery as an upstream source.

  6. Select Save in the upper right corner to save your changes. Select Save again if prompted to confirm your choices.

Connect to feed

  1. Create a personal access token with Packaging > Read & write permissions.

  2. 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)
    
  3. 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.

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. 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.

    A screenshot showing packages saved from upstream in an Azure Artifacts feed.