Unable to Resolve Package Source


I can’t seem to update any PowerShell module anymore

Today I ran into a problem on my Hyper-V test lab system

Whenever I ran Install-Module or Update-Module on my system, I’d get the error message:

1
2
Install-Module:
Unable to resolve package source 'https://www.powershellgallery.com/api/v2'

Unable to resolve package source
Unable to resolve package source

Now I received this error message, but surely I’m not alone in this, chances are you’re here because you experienced the same problem!
This can be a real pain in the ass, because chances are you just wanted to install/update one issue and now you’re stuck with a completely different issue eating up your time.

When trying to troubleshoot the issue, you can first try and see if there’s an issue with DNS or your connection:

1
Resolve-DnsName -Name powershellgallery.com

If that looks fine, trying to establish a connection to the site can be your next step:

1
Invoke-WebRequest 'https://www.powershellgallery.com/api/v2' -Verbose

This gave me the error

1
2
Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At line:1 char:1

Based on this Could not establish trust relationship for the SSL/TLS secure channel. it looks like this may be a TLS issue and

You can first try and force your system to talk over TLS1.2 using the following command:

1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::tls12

But if that doesn’t work you may need to upgrade to the latest PowerShellGet (2.2.5), which handles temporary compatibility with TLS 1.2 on legacy TLS systems:

1
Install-Module -Name PowerShellGet -Force

But here lies another issue… you can’t install/update a module if you can’t install a module…
So what you can do is download it on another machine that DOES have the proper connection/configuration, save it and copy it to your ‘broken’ system:

On your working machine:

1
Get-Module -Name PowerShellGet,PackageManagement -Listavailable

Confirm that these are the versions you want (at time of writing PowerShellGet is at version 2.2.5 and PackageManagement is at version 1.4.7).

Save them to a temporary folder (in this example C:\temp , change this accordingly):

1
Save-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Path C:\Temp

Only Saving PowerShellGet automatically takes along the PackageManagement module due to its dependency.
Now copy the modules from your working machine to your broken machine, be sure to place the module files under
C:\Program Files\WindowsPowerShell\Modules\ and be sure to merge the folders with currently existing ones.

In order for the new modules to be used instead of the old version, you’re best off to close and re-open a new PowerShell session.