08 September 2017

Install-Module - unable to resolve package source 'https //www.powershellgallery.com/api/v2/'

Trying to install a PowerShell module behind a proxy?
Chances are you're getting this error:

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

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

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

Now every command you run is sent and allowed through the proxy.

41 comments:

  1. Anonymous10/7/18 03:19

    Thank you! This worked for me, even when providing the proxy & credentials wouldn't work.

    ReplyDelete
  2. Anonymous30/8/18 09:20

    OMG you deserve a cookie!!!
    been busting my head with this for a week.....

    ReplyDelete
  3. Anonymous3/10/18 09:58

    Nice one! Saved me a lot of time and hassle thank you for this! :)

    ReplyDelete
  4. Thanks !

    ReplyDelete
  5. thank you man...works like a charm

    ReplyDelete
  6. Anonymous4/1/19 16:59

    Nice one, thanks

    ReplyDelete
  7. This worked for me, Thanks

    ReplyDelete
  8. Anonymous9/4/19 23:16

    You are simply awesome!! Thank you so much!!

    ReplyDelete
  9. Anonymous10/4/19 16:34

    Awesome, this worked after a lot of research and wrong paths.
    Thank you.
    Ovi

    ReplyDelete
  10. Is there a way to make this permanent as soon as powershell runs?

    ReplyDelete
    Replies
    1. Anonymous17/7/19 14:58

      add it to your $PROFILE

      Delete
  11. Anonymous4/10/19 01:50

    Thank you. Gold Star effort

    ReplyDelete
  12. thanks, this worked and is still applicable in 2020! :)

    ReplyDelete
  13. Sorry to spoil the party, but this dont work for me. :-(
    PS H:\> $webclient=New-Object System.Net.WebClient
    PS H:\> $webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
    PS H:\> Find-Module -Name PowerShellGet
    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 'PowerShellGet'.

    Dont have any more hair on my head to rip off!! Cant find the problem.

    ReplyDelete
    Replies
    1. Anonymous6/5/20 21:52

      This is a TLS problem. Enter this in your PowerShell:

      [Net.ServicePointManager]::SecurityProtocol = "tls12"

      Then run the command.

      Delete
    2. Can I upvote this 1000 times???
      Thank you Anonymous!!!

      Delete
    3. you are owsome! thanks a lot!

      Delete
    4. Anonymous13/5/20 14:27

      omg, thanks, I could blow you right now!

      Delete
  14. Anonymous29/4/20 17:30

    It didn't work for me either

    ReplyDelete
  15. Anonymous6/5/20 21:52

    This is a TLS problem. Enter this in your PowerShell:

    [Net.ServicePointManager]::SecurityProtocol = "tls12"

    Then run the command.

    ReplyDelete
  16. No this doesn't seem to work anymore. If you're installing or updating you have to download the msi file and do it manually. To update be sure to remove the previous version first. Par for the course that Msft doesn't take into account most of their customers are behind proxies and actually provide some guidance on this.

    ReplyDelete
    Replies
    1. Anonymous7/5/20 21:36

      This is an issue with PowerShell 5.1.. If you get version 6 or 7 from https://github.com/PowerShell/PowerShell/releases/tag/v7.0.0, or https://github.com/PowerShell/PowerShell/releases/tag/v6.2.3 everything works.

      Delete
  17. this works for me. Thanks a lot.

    ReplyDelete
  18. This worked for me as well, tested on two Windows 2016 servers.

    ReplyDelete
  19. PSVersion 5.1.14409.1018
    PSEdition Desktop
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}

    It's work! Thank you a lot !!!

    ReplyDelete
  20. PSVersion 5.1.17134.858
    PSEdition Desktop
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}

    It works, Thank you so much.

    ReplyDelete
  21. You saved my day, thanks

    ReplyDelete
  22. Still works perfectly in 2020!

    ReplyDelete
  23. It works awesome. Thank you so much. .

    ReplyDelete
  24. Hello Guys... request help this doesn't work for me on window server 2016 datacenter

    PS C:\Windows\system32> $webclient=New-Object System.Net.WebClient
    PS C:\Windows\system32> $webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
    PS C:\Windows\system32> Find-Module -Name PowerShellGet
    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 'PowerShellGet'.
    Try Get-PSRepository to see all available registered module repositories.
    At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:8873 char:9
    + PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
    n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage


    PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = "tls12"

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

    ReplyDelete
  25. Anonymous23/9/20 07:58

    Worked for me, thx!

    ReplyDelete
  26. Thank you so much

    ReplyDelete
  27. Anonymous27/7/21 09:48

    Its resolved my issue. Thank you so much.

    ReplyDelete
  28. Anonymous27/4/22 03:37

    I only had to change to TLS1.2 to get it to resolve: [Net.ServicePointManager]::SecurityProtocol = "tls12"

    ReplyDelete