How to Fix PowerShell Unable to Resolve Package Source

Table of Contents

Unable to resolve package source

When trying to install a module via Powershell on a new machine, I was getting the following error:

PS C:\Users\Administrator> Find-Module AzureRM
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 'AzureRM'. Try
Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1360 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

This issue occurs when PowerShell tries to connect to the PowerShell Gallery repository using legacy TLS/SSL protocols instead of the current TLS 1.2 or the newer TLS 1.3.

The resolution

We need to make sure we force powershell to be using TLS 1.2 due to the deprication of TLS 1.0, the destination that hosts the module wont accept a TLS 1.0 connection.

To fix it, run an elevated PowerShell prompt as usual. This will force your PowerShell to use TLS 1.2 rather than TLS 1.0.

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

Now you can see if the package is available from the gallery with the Find-Module command, and now when trying to reinstall you should no longer get the error.

PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\> Find-Module AzureRM

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
6.13.2     AzureRM                             PSGallery            Azure Resource Manager Module

Leave a Comment

Required fields are marked *