NuGet Unable to download from URI error Powershell

Among the most useful cmdlets in PowerShell is ‘Install-Module.’ It facilitates the download and installation of one or more modules from a repository onto the local computer. Simply specify the name of the module after this cmdlet; if the module exists in the repository, it will be installed on your device. By default, the newest version of the module is downloaded onto your system.

When executing the ‘Install-Module‘ command, such as ‘Install-Module ExchangeOnlineManagement‘ PowerShell may prompt an error indicating that the NuGet provider is required to continue. Specifically, PowerShellGet requires NuGet provider version 2.8.5.201 or newer to interact with NuGet-based repositories.

The error message provides a PowerShell command for manually installing the NuGet provider on your device. You can use the command: ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force‘. It’s important to note that PowerShell 5.1 comes with PowerShellGet version 1.0.0.1, which does not include the NuGet provider.

1. Find the Version of Powershell

First, check the version of PowerShell you are using with the command $PSVersionTable.

Check Powershell version

$psversiontable.PSversion

2. Get the Version of PowershellGet

Next, check the version of PowerShell you are using with the command Get-Module cmdlet. If there are multiple versions of PowerShellGet listed, the most recent version will be used.

Check the version of PowershellGet

Get-Module PowerShellGet -Listavailable

Check Enabled security protocols

[Net.ServicePointManager]::SecurityProtocol

3. Enable TLS 1.2 in your powershell session

Powershell Gallery does not support TLS 1.0 and TLS 1.1 protocols. You should disable TLS 1.0 and TLS 1.1 as most of the applications do not support these protocols. If you are using a script then you can include below line in your powerhell script. By default, Powershell is not configured to use TLS 1.2. To access Powershell Gallery, TLS 1.2 or higher is required.

If you are using powershell console for installing modules or running commands then you can copy and paste below code into the powershell console. This should enable powershell to use TLS1.2.

Enable TLS 1.2 in Powershell session

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

Other Useful Articles on Disabling Weak TLS Protocols

Disable TLS 1.0 and TLS 1.1
It’s recommended to disable TLS 1.0 and TLS 1.1 on all your devices. You can refer to the blog posts below for details on how to accomplish this using various methods on different Windows operating systems.
How To Disable TLS 1.0 And TLS 1.1 On Windows Servers
Disable TLS 1.0/TLS 1.1 using Powershell on Windows 10/11
Disable TLS 1.0 And TLS 1.1 For Internet Explorer Using Intune

4. Enable Strong Cryptography in .NET 4.5+

To configure .NET Framework to support strong cryptography, use the following PowerShell commands. These commands will make changes to the registry key, so ensure you run them from an elevated version of PowerShell. This is applicable for .NET Framework 4.5 or higher.

Set Strong Cryptography on 64 bit .Net Framework (version 4 and above)

Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

Set Strong Cryptography on 32 bit .Net Framework (version 4 and above)

Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

5. Restart Powershell and confirm Security Protocols

After setting the security protocol to TLS 1.2 and configuring the strong cryptography registry keys, restart your PowerShell session and launch it again. Now, check the security protocols once more to confirm the changes.

Check Enabled Security Protocols

[Net.ServicePointManager]::SecurityProtocol

6. Install the Latest Version of PowerShellGet

You can install NuGet and PowerShellGet using the following commands:

Install Latest version of NuGet

Install-PackageProvider -Name NuGet -Force

Install PowerShellGet

Install-Module PowerShellGet -AllowClobber -Force

Register Powershell Gallery as trusted repository

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

7. Download NuGet Provider for Powershell manually

If the steps provided previously do not resolve the issue, you can also download the NuGet Provider manually using the following link: Download NuGet Provider. The location for NuGet Provider is: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208.

Install Nuget Using Powershell

To install NuGet using PowerShell, run the following commands:

  1. Launch PowerShell as an administrator.
  2. Install NuGet using the ‘Install-PackageProvider‘ cmdlet.
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force

This will install NuGet in C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.201. Keep in mind that you might have a different version of NuGet installed, so the version number may vary in the path.

  1. Check the NuGet Provider and import it using the ‘Import-PackageProvider‘ cmdlet.
Get-PackageProvider -ListAvailable
Import-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201

Conclusion

Powershell Gallery serves as a central repository for storing and sharing PowerShell scripts and modules. Therefore, it’s easy to use the ‘Find-Module‘ command to locate any PowerShell module on the gallery. Once you find a module, you can use the ‘Install-Module’ command to download and install it on your device.

To fulfill these requirements, it’s necessary to have the NuGet provider and PowerShellGet installed on your device. Newer versions of PowerShell typically include the NuGet provider. PowerShell 6.0 comes with version 1.6.0 of PowerShellGet, and PowerShell 7.0 comes with version 2.2.3 of PowerShellGet.

Leave a Comment

Discover more from TechPress

Subscribe now to keep reading and get access to the full archive.

Continue reading