PowerShell unable to resolve package source

1 Min Read

PowerShell is unable to resolve the package source.

When trying to import an excel module in PowerShell an enterprise PC I encounter the next error:

unable to resolve package source ‘https //www.powershellgallery.com/api/v2/’

The reason is very simple – trying to install a PowerShell module behind a proxy?

Turns out it isn’t allowed through a proxy server, run this in a PowerShell session and try again:

$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredent
3 Comments
  • You also need to run:
    [Net.ServicePointManager]::SecurityProtocol = “tls12”
    after these lines to make it work.
    At least I needed to.

  • Awesome , I was struggling with this for 2 hours , I though antivirus was blocking this but after running these lines it finally worked !!! thank you

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

    [Net.ServicePointManager]::SecurityProtocol = “tls12

    what exactly these lines do??

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version