#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

How to fix "System.InvalidOperationException: PowerShell Gallery is currently unavailable."

koskila
Reading Time 3 min
Word Count 473 words
Comments 8 comments
Rating 5 (5 votes)
View

This article explains how to fix an issue when updating a module in PowerShell. The error is something along the lines of: "System.InvalidOperationException: PowerShell Gallery is currently unavailable. Please try again later."

The whole error looks something like the one below, although you can probably get it for many different commandlets.

Failed updating module 'SharePointPnPPowerShellOnline' version 3.19.2003.0. Update the module and then try again. Error Could not execute Command. The error: System.InvalidOperationException: PowerShell Gallery is currently unavailable.  Please try again later.

The main point is the latter part of the error: PowerShell Gallery is currently unavailable. This, quite simply, stops you from installing or updating any modules, as you can't access the PowerShell gallery, that hosts the modules.

Luckily, like usual, there are a few ways to fix this!

Solution

Time needed: 10 minutes.

How to fix "System.InvalidOperationException: PowerShell Gallery is currently unavailable." in 1 to 5 easy steps

  1. Verify whether you have a recent enough PowerShell version

    Run this:

    Get-Host | Select-Object Version

    If it's 5.1 or newer, you're probably good! If not, download latest version here: https://www.microsoft.com/en-us/download/details.aspx?id=54616

  2. Verify you have the right repository

    Run this commandlet in your PowerShell:

    Get-PSRepository

    Your output is somewhat like this:

    Name InstallationPolicy SourceLocation ---- ------------------ -------------- PSGallery Untrusted https://www.powershellgallery.com/api/v2

    There's 3 things that COULD be wrong in this case. Depending on the exact error message you got, either:

    1. The source needs to be trusted (see step 3)
    2. The SourceLocation is not accessible (see step 4)
    3. The SourceLocation URI needs to end with '/' (see step 5)
  3. Set your PSGallery to be trusted

    Run the following commandlet:

    Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

    If you get an error like this:

    Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.

    Then you can't access the URI either because it doesn't have a trailing slash (see step 5) or because it's not accessible (see step 4).

    And if you get an error like:

    Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.

    Then, well, run:

    Register-PSRepository -Default

    To see if it helps!

  4. Verify you have access to the URI

    Open up your browser and navigate to this address:
    https://www.powershellgallery.com/api/v2/

    If you get something like the screenshot below, you access this address, but your PowerShell can't.

    The expected XML output of https://www.powershellgallery.com/api/v2/

    In this case your PowerShell is probably unable to access it due to a mismatch in TLS versions - try running this commandlet to enable TLS 1.2 and see if it helps:

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

  5. Fix the PSGallery's URI

    In case the PSGallery URI does not end with a trailing slash, run the following commands (this'll set the new PSRepository to be Trusted as well):

    Unregister-PSRepository PSGallery Register-PSRepository -Name PSGallery -SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted

    If you get an error after running this, you can also try naming your Repository something else.


And with that, you should be good!

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Elliott Balsley
2021-02-19 18:36:10)
Thanks for this! It was not working until I added the trailing slash to the URL. But to do this I had to give it a new name like PSGallery2 or else I got this error:
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
Antti K. Koskela
2021-02-25 17:50:44
Thanks for your comment, Elliott! Yeah, PowerShell repositories can be a lot of fun - sometimes they work without the slash, sometimes they don't, sometimes they change required SSL/TLS versions, sometimes they just shutdown whatever long-forgotten server was running the Web API and only reboot it after enough people complain on Twitter... And this isn't made any easier by having multiple, largely independent flavors and versions of PowerShell available, let alone the absolute plethora of competing modules (just look at AzureAD for example!) But I digress. One of my favorite topics to rant about... :) Have a good one!
Laurentiu
2021-02-27 15:47:50)
Thank you so much.
Antti K. Koskela
2021-02-27 23:29:37
Happy to be of help, Laurentiu!
Paul
2021-10-08 19:38:23)
Very helpful and thanks! I've been through this a few times now because each time I didn't document my solution and thus had to refigure it out. So this was really nice, but... Just want to mention nothing worked until, like Elliot noted, "Register-PSRepository -Default" was in the error response. So ran that cmd as is and it worked. Thanks again!
2021-11-16 22:37:50
Hi Paul! Thanks for your comment and apologies for my slow response 😅 I'll modify my post to accommodate that point. 😊
David Trevor
2022-09-27 11:03:52)
Big thanks to you, I had multiple servers in China where it would not install a module from PSGallery. Unregistering the repository and registering it under a new name made the download work instantly! What a joke :D Unregister-PSRepository PSGallery Register-PSRepository -Name "abc" -SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted
2022-09-27 16:14:38
Thanks for the kind comment! Yeah, it's not pretty. But I'm happy to hear it helped :)
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-05T20:02:20Z