Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell error saying the gallery is unavailable try again later

Tags:

powershell

I am running into this issue where iam unable to install any modules. even when i try to register i get this error. any ideas on resolving this appreciate it.

PS C:\Users\abc> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable.  Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4095 char:9
+         Get-PSGalleryApiAvailability -Repository $Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
 
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
    + FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
 

PS C:\Users\abc> $PSVersionTable

Name                           Value                                                                                                                                                                 
----                           -----                                                                                                                                                                 
PSVersion                      5.1.17134.858                                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                               
BuildVersion                   10.0.17134.858                                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                                   
SerializationVersion           1.1.0.1                                                                                                                                                               

-- adding some more commands

Find-PackageProvider -Name nuget
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Find-PackageProvider : No match was found for the specified search criteria and package name 'nuget'. Try
Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Find-PackageProvider -Name nuget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:FindPackageProvider) [Find-PackagePro
   vider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvid
   er

Register seems to complete without any errors, but nothing gets added

PS C:\Users\abc> Register-PSRepository -Default
PS C:\Users\abc> Get-PSRepository
WARNING: Unable to find module repositories.
PS C:\Users\abc>

PS C:\Users\abc> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Users\abc> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable.  Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4095 char:9
+         Get-PSGalleryApiAvailability -Repository $Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability

Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
    + FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository

PS C:\Users\abc> Get-PSRepository
WARNING: Unable to find module repositories.
like image 353
sbolla Avatar asked Sep 22 '20 13:09

sbolla


2 Answers

Try forcing tls 1.2. This solves most powershell gallery issues

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

like image 138
Peter the Automator Avatar answered Nov 16 '22 02:11

Peter the Automator


Not really a solution, but rather an FYI piece. This also seems to happen regularly every three months now when TLS cert in https://www.powershellgallery.com/api/v2 expires. For some reason, Microsoft are struggling to get the cert renewal to work properly.

When this happens, none of the above mentioned solutions will work. In fact, this is happening right now, as I type this... https://github.com/PowerShell/PowerShellGallery/issues/166

To see if the issue is caused by the expired (or otherwise invalid) cert, just open this URL https://www.powershellgallery.com/api/v2 in a browser and see if the browser complains about the certificate.

If you need to make it work just this one time, you can try tricking Powershell into ignoring invalid certificates like so:

[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};

...but be warned:

a) this is a bad practice and you shouldn't really have it as a permanent solution because this will expose you to man-in-the-middle attack; and

b) this may not help you because Microsoft guys usually disable PSGallery API when this situation happens. To check if the API is disabled right now, run:

# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable.  Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4302 char:9
+         Get-PSGalleryApiAvailability -Repository $Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability

Update: Also look here for any current ongoing issues with PSGallery: https://github.com/PowerShell/PowerShellGallery/blob/master/psgallery_status.md

like image 35
Oleg Kazakov Avatar answered Nov 16 '22 04:11

Oleg Kazakov