Using PowerShellGet with Azure Artifacts

We have improved the experience with PowerShell Get and private nuget feeds by focusing on pain points using an Azure Artifacts feed.
We addressed pain points by enabling/documenting the following features:

  • Non-PAT for package management
  • Credential persistence in Register-PSRepository

These improvements will effect the following cmdlets:

  • Register-PSRepository
  • Set-PSRepository
  • Find-Module/Script
  • Install-Module/Script
  • Update-Module/Script
  • Save-Module/Script
  • Publish-Module/Script

What is Azure Artifacts and Why would I use it?

Azure Artifacts is an Azure Dev Ops service which introduces the concept of multiple feeds that you can use to organize and control access to your packages. In other words it is a place for storing and sharing packages with controlled access through Azure Dev Ops. A common use scenario for Azure Artifacts with PowerShellGet is for organizations which need a controlled access feed for sharing their private internal packages and vetted external packages within their organization. Package owners may also want to use Azure Artifacts as part of their CI/CD pipeline in Azure Dev Ops. For more information on Azure Artifacts, check out their documentation.

Getting started with Azure Artifacts with PowerShellGet

Since these fixes were introduced into PackageManagement, verify you have at least version 1.4.1 of the PackageManagement module
to do this run Get-InstalledModule PackageManagement . If you do not have this version 1.4.1 or higher run the command
Update-Module PackageManagement and then refresh your PowerShell session.

The next step is to create an Azure Artifacts feed, since Azure Artifacts is an Azure Dev Ops service you will need to create an Azure Dev Ops account if you don't already have one.

Once you gave an account you can create an Azure Artifacts feed. To do this, follow these steps. Return here for instructions on connect to the feed and publish packages.

The other component you will need is the Azure Artifacts credential provider. The credential provider comes pre-installed with , so if you have VS 15.9, you don't need to install anything. Otherwise the steps for installing the credential provider, which are platform dependent are provided here.

To register your feed as a PSRepository you will need a name, source location,
publish location, and credential. The name is what you will call the PSRepository and can be anything you chose
in this example we call it “myAzArtifactsRepo”. Your source location, and publish location will be the same uri and will be the
format: “https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2“. You have a couple of options for your credential, you can either use a personal access token (PAT) or you can enable non-PAT .
For more information on this check out the documentation.

You are now ready to register your Az Dev Ops feed as a PSRepository using the
following command:

Register-PsRepository myAzArtifactsRepo -SourceLocation  "https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2" -credential $credentials

Let's publish a PowerShell Gallery package to our Azure Dev Ops feed.
To do this, you need to first save the module then, publish it using the following commands:

Save-Module -Name SHiPS -Repository PSGallery -Path '.'
Publish-Module -path "pathtomodule"SHiPS -Repository myAzArtifactsRepo -NuGetApiKey 

Now that we have some packages let's find and install them:

Find-module  -name SHiPS -Repository myAzArtifactsRepo

Install-Module -name SHiPS -Repository myAzArtifactsRepo

Now that you can manage packages on your feed, you may want to share it with other users. To manage the access to your feed use the feed settings in Azure Artifacts. For more information on this check out the documentation.

Getting Feedback

If you encounter any issues we would love to hear about it on our GitHub page.
Please file an issue letting us know what we can do to make your experience better.

The post Using PowerShellGet with Azure Artifacts appeared first on PowerShell.

 

This article was originally published by Microsoft's Secure Blog. You can find the original article here.