When trying to download Powershell modules on Server 2016/2019, you may come up against the following error message;

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.

This is linked to the insecure security protocols being used by powershell and it will need to be set to a supported protocol, this could be either if you were behind a proxy configured a certain way or the site you are connecting to only supports certain protocols.

For example, if you were trying to install the AzureAD module and it returned the following error

PS C:\windows\system32> install-module AzureAD

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'AzureAD'.

Try Get-PSRepository to see all available registered module repositories.

At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21

+ ...          $null = PackageManagement\Install-Package @PSBoundParameters

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex

   ception

   + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

You can check what current security protocols you are running by the following command;

[Net.ServicePointManager]::SecurityProtocol

If you see Ssl3, TLS as below it means its only setup for SSLv3 and TLS1.0 both now classed as insecure.

To change this to use TLS 1.2 run the following command then try your original command again

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

If that fails, it could be that a web proxy is in the way and the protocol needs to be specified in the WebClient,

$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = "tls12"

Hopefully one of these 2 commands has fixed the issue and you should now be able to download your original file.

Please be aware these are both powershell session only commands and will be lost once the powershell window is closed.

If you need this as part of a script add the line at the top.