How to Installing the NuGet Package in PowerShell

  1. Understanding NuGet Installation Challenges in PowerShell
  2. Find the PowerShell Version
  3. Transport Layer Security Protocols in PowerShell
  4. Solution on Installing the NuGet Package Properly
How to Installing the NuGet Package in PowerShell

NuGet is a package management tool from the .NET framework, and it is similar to PowerShellGet, MSI packages that support several commands and packages to work with PowerShell.

For example, we may need NuGet to run specific scripts. However, we may encounter errors when installing the NuGet package in Windows PowerShell.

This article will learn why errors are happening and the step-by-step guide for installing the NuGet provider for PowerShell.

Understanding NuGet Installation Challenges in PowerShell

Open PowerShell as administrator. Run the command Install-Module PowerShellGet -Force to install the NuGet package.

When asked for confirmation to install the NuGet provider, press the Y key and press Enter.

Install-Module PowerShellGet -Force

After executing, if you have encountered these problems when installing the NuGet package, we may need to do additional steps to install the package successfully.

  • WARNING: Unable to download from URI.
  • WARNING: Unable to download the list of available providers. Check the internet connection.
  • Unable to find package provider ‘NuGet’. It may not be imported yet.

The article’s next section will discuss the step-by-step procedure for properly installing the NuGet package.

Find the PowerShell Version

We must first find the PowerShell version that is running on the system.

To do this, we may use the GetHost cmdlet or export the $PSVersionTable variable.

Get-Host | Select-Object Version
$PSVersionTable

Output:

Version
-------
5.1.22000.282

PowerShell 5.1 enables SSL and TLS for secure HTTP connections by default, in which we will need to upgrade to install the NuGet package.

Transport Layer Security Protocols in PowerShell

To check the supported security protocols on the system, we may use the snippet below.

[Net.ServicePointManager]::SecurityProtocol

Output:

Ssl3, Tls

The security protocols defined by default are SSL 3.0 and TLS 1.0.

Unfortunately, both of the security protocols are deprecated. Therefore, only TLS 1.2 and TLS 1.3 are approved at the moment of writing.

Solution on Installing the NuGet Package Properly

We’ll enable TLS 1.2 on the system. Run both cmdlets to set .NET Framework strong cryptography registry keys.

Then, restart PowerShell and check if the security protocol TLS 1.2 is added. Install the PowerShellGet module.

The first cmdlet sets 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

The second cmdlet sets 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 check if TLS versions have now been updated.

[Net.ServicePointManager]::SecurityProtocol

Output:

Tls, Tls11, Tls12

Another workaround is to reassign the security protocol command manually.

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

Output:

Tls12

Once TLS 1.2 is installed, rerun the package installer, and it should work perfectly this time around.

Install-Module PowerShellGet -Force
Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn