When you try to install PowerShell modules from the online PSGallery, you may see the following error:
Install-Module SqlServer WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'sqlserver. Try Get-PSRepository to see all available registered module repositories. NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
The problem may occur on Windows 10, Windows Server 2016, or previous Windows versions. The reason is that PowerShell tries to use a legacy and insecure TLS 1.0 protocol to connect to the PSGallery repository by default. Since April 2020, the PowerShell Gallery accepts connecting to the NuGet provider using TLS 1.2 only.
If TLS 1.0 and TLS 1.1 are not disabled in Windows, run the command below to use TLS 1.2 in the current PowerShell session:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
TLS 1.2 is supported in all Windows versions starting from Windows 8 and Windows Server 2012. You can display a list of supported TLS versions in PowerShell:
[enum]::GetNames([Net.SecurityProtocolType])
In order to enable TLS 1.2 support in Windows 7 SP1/Windows Server 2008 R2, install KB3140245 and the MicrosoftEasyFix51044.msi fix.
Now you can install or update the module from PowerShell Gallery:
Next time you open your PowerShell console, you will have to enable TLS 1.2 protocol again. You can display protocol versions used in PowerShell for connection as follows:
[Net.ServicePointManager]::SecurityProtocol
To avoid enabling TLS 1.2 each time you open PowerShell, you may change the default TLS version for .NET Framework. To do it, make the following changes to the registry using PowerShell:
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
netsh winhttp show proxy
You can import proxy server settings from Windows:
netsh winhttp import proxy source=ie
A similar error when installing PowerShell modules Unable to download from URI is described in the previous article.