Registering PS Repositories gives misleading error message when your account does not have authorisation

Sebastian Rogers
2 min readFeb 28, 2022

TL;DR When using Register-PSRepository ‘Location’ is an invalid Web Uri may instead mean you are not authorised to use the valid Web Uri

The specified Uri ‘https://pkgs.dev.azure.com/MyAzureDevOps/MyProject/_packaging/MyRepository/nuget/v2' for parameter ‘Location’ is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.

This one threw us for several hours. We were getting it in an Azure DEVOps Pipeline.

The URI was valid, we could open it up in a browser and it showed a correct feed.

In the end it turns out to be a very loose error message in that the Uri is valid but the process calling it is not authorised to use it.

We proved this by using the Register-PSRepository PowerShell command with and without credentials.

However we were doing this in a pipeline, see below, using the SYSTEM_ACCESSTOKEN. It was working in two projects, including the one the Azure Artifact Feed was defined in, but not in any others.

So what was the difference?

It all comes down to the “Limit job authorization scope to current project for non-release pipelines” Azure DEVOps project’s setting for the project that is using the feed.

With this set, which is the default, then SYSTEM_ACCESSTOKEN is blank, hence the credentials are invalid and you get the error message.

The specified Uri ‘https://pkgs.dev.azure.com/MyAzureDevOps/MyProject/_packaging/MyRepository/nuget/v2' for parameter ‘Location’ is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.

With it unset then SYSTEM_ACCESSTOKEN is populated and the credentials are properly created.

For reference here is the example code for using SYSTEM_ACCESSTOKEN to authenticate.

TL;DR When using Register-PSRepository ‘Location’ is an invalid Web Uri may instead mean you are not authorised to use the valid Web Uri

--

--

Sebastian Rogers

Technical Director for Simple Innovations Ltd. First paid for code in 1980, but still has all his own hair.