DEV Community

Cover image for PowerShell disabled support for TLS 1.0 for the Gallery - Update-Module and Install-Module broken
Robin Kretzschmar
Robin Kretzschmar

Posted on

PowerShell disabled support for TLS 1.0 for the Gallery - Update-Module and Install-Module broken

Microsoft announced that the PowerShell Gallery has deprecated Transport Layer Security (TLS) versions 1.0 and 1.1 as of April 2020

To provide the best-in-class encryption to our customers

Announcement, details and reasons can be found on DevBlogs.microsoft.

Awesome news!
... leaving Update-Module and Install-Module broken!

Running Update-Module or Install-Module will now throw an error like one of the two following:
Error unable to find repository

PowerShell Gallery currently unavailable

Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
........... (cutted)
Enter fullscreen mode Exit fullscreen mode
PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2'. Use Get-PSRepository to see all available repositories.
........... (cutted)
Enter fullscreen mode Exit fullscreen mode

Fixing it (Microsoft way)

You just got the error and didn't try any wild ideas to fix it and poked around? Good, execute the migration command Microsoft provided in their announcement and you'll be good to go:

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

This will change the security protocol to TLS 1.2.

Already messed around? Fix it with this

If you already messed around with various commands like trying a proxy, removing the repository of PSGallery and stuff or getting the second error, you can fix it with the following commands:

Impatient, in a hurry or not interested in details

No judgement here.
Just looking for the commands? Quick summary:

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

Commands with explanations

Set the TLS 1.2 protocol first:

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Enter fullscreen mode Exit fullscreen mode

Now register the PSGallery again:

Register-PSRepository -Default -Verbose
Enter fullscreen mode Exit fullscreen mode

Check the success with Get-PSRepository and you should see an output like this:

PS C:\windows\system32> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
Enter fullscreen mode Exit fullscreen mode

Set the Installation Policy of PSGallery to Trusted:

Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Enter fullscreen mode Exit fullscreen mode

Result:

PS C:\windows\system32> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2
Enter fullscreen mode Exit fullscreen mode

Now you'll be able to run Update-Module and Install-Module successful again.

Top comments (5)

Collapse
 
onolisk profile image
Duane

Great article, concise.

Collapse
 
vayin profile image
vinay ayinapurapu

this helped me today after lot of juggling with other steps. Thank you so much..

Collapse
 
samanovais profile image
SamanOvais

i know it should have worked but the installation policy is still untrusted🤦‍♀️ any suggestions

Collapse
 
darksmile92 profile image
Robin Kretzschmar

try running Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted first without and then again with elevated privileges (admin)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.