Unable to install NuGet provider for PowerShell on Windows Server 2016


I recently had a case at a customer, where we saw an error and unable to install packages from the PowerShell Gallery on an Windows Server 2016.

A little info on the background. In our scenario, it was during the install of the Microsoft Azure MFA extension for the Network Policy Server (NPS). As part of the configuration process for the Azure MFA Extension, it requires you to run the post install PowerShell script, that installs some pre-quirements for the MFA extension.

The same error could also be seen, when trying to install any packages from the PowerShell Gallery, such as: Install-Module MSOnline or Install-Module AzureAD.

The errors seen during the install:

The reason why it fails, is because on Windows Server 2016, TLS 1.2 is not by default enabled and this is needed for communication with NuGet and PowerShell Gallery.

The Solution or workaround

The solution is to run the following command in PowerShell, to enable TLS 1.2 and then after just the inital install commands to install from PowerShell Gallery og using the NuGet Provider:

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