NuGet Unable to download from URI error Powershell

One of the most useful cmdlet in powershell is Install-Module. It downloads one or more modules from a repository, and installs them on the local computer. You just have to specify the name of the module after this cmdlet, if the module exists in the repository, it gets installed on your device. By default newest version of the module is downloaded on your system.

When you run Install-Module command for example: Install-Module Exchangeonlinemanagement, Powershell will throw an error message that NuGet provider is required to continue. PowershellGet requires NuGet provider version 2.8.5.201 or newer to interact with NuGet-based repositories.

There is a powershell command given in the error message which says how NuGet provider can be installed manually on your device using Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force. Powershell 5.1 comes with PowerShellGet version 1.0.0.1 which does not include NuGet provider.

Find the version of Powershell you are using

First, check the version of Powershell you are on using a command $psversiontable.

Check Powershell version

$psversiontable.PSversion

Find PowershellGet version you are using

First, check the version of Powershell you are on using a command Get-Module cmdlet. If there are multiple versions of PowershellGet listed, then the most recent version will be used.

Check the version of PowershellGet

Get-Module PowerShellGet -Listavailable

Check Enabled security protocols

[Net.ServicePointManager]::SecurityProtocol

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.

Disable TLS 1.0 and TLS 1.1
Its recommended to disable TLS 1.0 and TLS 1.1 on all your devices. You can refer to below blog posts which provides details on how it can be done using various methods on different Windows OS.

How To Disable TLS 1.0 And TLS 1.1 On Windows Servers
How To Disable TLS 1.0 And TLS 1.1 Using Powershell On Windows 10
How To Disable TLS 1.0 And TLS 1.1 Using Powershell On Windows 11
Disable TLS 1.0 And TLS 1.1 On Windows 10
Disable TLS 1.0 And TLS 1.1 For Internet Explorer Using Intune

Enable TLS 1.2 in Powershell session

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

Enable strong cryptography in .NET 4.5+

Configure .NET Framework to support strong cryptography. To enable strong cryptography in .NET Framework 4.5 or higher, you can use below powershell commands. The commands will make changes to the registry key. Please run the commands from elevated version of powershell.

Set strong cryptography on 64 bit .Net Framework (version 4 and above)

Set-ItemProperty -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)

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

Restart Powershell and confirm Security Protocols

After you have set the security protocol to TLS 1.2 and set strong cryptography reg keys, you can restart your powershell session and launch it. Now, check the security protocols again to confirm.

Check Enabled security protocols

[Net.ServicePointManager]::SecurityProtocol

Installing the latest version of PowerShellGet

You can Install NuGet and PowerShellGet using below commands:

Installing NuGet

Install-PackageProvider -Name NuGet -Force

Install PowerShellGet

Install-Module PowerShellGet -AllowClobber -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

How to download NuGet Provider for Powershell manually

This should fix this issue and you would be able to run Install-Module command to install powershell modules from Powershell gallery. In case the steps given in this post does not resolve this issue, you can also download NuGet Provider manually using below link. The location for NuGet Provider is: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208

Download NuGet Provider manually

https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll

Conclusion

Powershell Gallery is a central place to store and share powershell scripts and modules. Therefore, its very easy to simply use Find-Module command to find any Powershell module from Powershell gallery. If you find a module, you can use Install-Module command to download and Install this PS module on your device.

However, the requirement for this is to have NuGet provider and PowershellGet installed on your device. Newer version of Powershell already include NuGet provider and therefore, it does not have to be installed separately. Powershell 6.0 comes with version 1.6.0 of PowerShellGet. Powershell 7.0 comes with version 2.2.3 of PowerShellGet.