PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Register-PSRepository not able to register HTTPS Source

Open varunmankal opened this issue 3 years ago • 2 comments

Ran the following commands in RHEL 7

Steps to reproduce

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/powershell-7.1.0-1.rhel.7.x86_64.rpm
pwsh
Register-PSRepository -Name testing -Source https://internal.server/api/nuget/mods

Expected behavior

Register the repository without error

Actual behavior

Register-PSRepository: The specified Uri 'https://internal.server/api/nuget/mods' for parameter 'SourceLocation' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Linux 5.4.17-2036.100.6.1.el7uek.x86_64 PowerShell/PowerShell#2 SMP Thu Oct 29 17:04:48 PDT 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

varunmankal avatar Dec 09 '20 21:12 varunmankal

The Register-PSRepository cmdlet is part of the PowerShellGet module and isn't managed in this repo. This bug should be reported to https://github.com/PowerShell/PowerShellGetv2.

While the message is misleading, this error can also be shown if the URI is not reachable as per this check. I recommend you try out this code to see what happens

# Change to your actual `-Source` value
$endpoint = 'https://internal.server/api/nuget/mods'

$handler = [Net.Http.HttpClientHandler]::new()
$handler.UseDefaultCredentials = $true
$httpClient = [Net.Http.HttpClient]::new($handler)
$response = $httpClient.GetAsync($endpoint)

"{0:d} {0}" -f $response.Result.StatusCode

There's a good chance this is due to either an unreachable host or potentially certificate validation problems.

GitHub
PowerShellGet is the Package Manager for PowerShell - PowerShell/PowerShellGetv2

jborean93 avatar Dec 10 '20 05:12 jborean93

In addition to @jborean93: use Nuget explorer NUGet explorer or equivalent RHEL GUI tool to validate your nuget source.

Also, check if NuGet is present as a provider in PowerShell https://docs.microsoft.com/en-us/powershell/module/packagemanagement/get-packageprovider?view=powershell-7.1

The Get-PackageProvider cmdlet returns a list of package providers that are connected to Package Management. Examples of these providers include PSModule, NuGet, and Chocolatey. You can filter the results based on all or part of one or more provider names.

peppekerstens avatar Dec 10 '20 10:12 peppekerstens