51

I tried to install Docker on activated windows server 2016 standard. I executed “Install-Module -Name DockerMsftProvider -Repository PSGallery -Force” but failed. It suggested that can not find PSGallery. I executed "Get-PSRepository".

The error:

WARNING: Unable to find module repositories.

I googled 3 ways to solve it but none of them worked.

  1. I executed Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Verbose -Force successfully.

  2. I installed chocolatey successfully.

  3. I execute "powershell Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted" but failed. It asked me to use "Register-PSRepository -Default".

I tried "powershell Register-PSRepository -Default -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted" but still failed.

How can I solve this problem?

TylerH
  • 20,799
  • 66
  • 75
  • 101
yuhan.dai
  • 511
  • 1
  • 4
  • 4

6 Answers6

79

With the deprecation of TLS 1.0 and 1.1 for PowerShell Gallery as of April 2020, the cmdlets Update-Module and Install-Module became broken. Thus, according to this article, some commands need to be executed to bring them alive again:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck

If that still doesn't work, then run the following commands:

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Register-PSRepository -Default -Verbose
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

TLS 1.0 and 1.1 were also recently deprecated at NuGet.org: nuget.org deprecated TLS 1.0 and 1.1 But that was also previously announced.

Alexandre
  • 1,132
  • 1
  • 10
  • 21
35

Simply running Register-PSRepository -Default (without any additional parameters) worked for me. After that, the Gallery was successfully registered:

PS C:\Windows\system32> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2/
Daibhi O Domhnaill
  • 1,137
  • 9
  • 10
20

My problem was the missing Proxy config

best solution from comments: https://www.zerrouki.com/working-behind-a-proxy/
thanks to @Vadzim


In PowerShell open Profile

PS> notepad $PROFILE

this opens Notepad with your profile setting, will be created of not exists.
then add:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

somehow my local proxy is set but doesn't work. same problem later with Docker, =>

> PS> [Environment]::SetEnvironmentVariable("HTTP_PROXY", http://username:password@proxy:port/", [EnvironmentVariableTarget]::Machine)

then restart docker service

Andre
  • 662
  • 1
  • 8
  • 19
  • 1
    Take a look also at https://www.zerrouki.com/working-behind-a-proxy/ and https://spaghettidba.com/2017/12/19/recovering-the-psgallery-repository-behind-a-corporate-proxy/ – Vadzim Feb 11 '18 at 08:54
  • 1
    It would be beneficial to your answer to quote the better parts then. ) – Vadzim Feb 12 '18 at 07:21
  • I've seen this answer mentioned a lot but I'm having the error on my home PC with no proxy... – KERR May 12 '20 at 11:43
  • 1
    For PowerShell Core v7, this is what works: `[System.Net.Http.HttpClient]::DefaultProxy = New-Object System.Net.WebProxy('http://127.0.0.1:8888', $true, @(";*.bypassdomain.com"))` – Janis Veinbergs Dec 07 '21 at 09:32
  • Thank you! This is exactly what I was missing – MKANET Sep 29 '22 at 21:53
7

I got a similar message. I ran Register-PSRepository -default and it registered ok. Then I ran Set-PSRepository -Name PSGallery -InstallationPolicy Trusted. I didn't combine the commands, but it worked.

I spent over an hour trying to pass credentials to the proxy the same way I do for Exchange Online, but no love. I disconnected and used our guest WiFi instead.

mybrave
  • 1,662
  • 3
  • 20
  • 37
0

One more thing which hasn't been mentioned. You would indeed need to run

notepad $profile

and copy paste this bit changing your proxy details:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials =  System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

But if you have HTTPS Inspection turned on, you might want to add the Man-in-the-middle Certificate to the "Trusted Root Certification Authorities"

elemer82
  • 170
  • 1
  • 9
0

Configuring correct Tls version resulted in the following errors:

PS /> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12                                  
PS /> Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck
Install-Package: No match was found for the specified search criteria and module name 'PowerShellGet'. Try Get-PSRepository to see all
available registered module repositories.
PS /> Get-PSRepository -Verbose
WARNING: Unable to find module repositories.

If you are working behind a corporate proxy service you might need to add trust to the CA.

cp my.crt /usr/local/share/ca-certificates/
update-ca-certificates

After updating our trust store we are able to query the powershell repository.

PS /> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
Erik
  • 133
  • 15