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:
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
........... (cutted)
PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2'. Use Get-PSRepository to see all available repositories.
........... (cutted)
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
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
Commands with explanations
Set the TLS 1.2 protocol first:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Now register the PSGallery
again:
Register-PSRepository -Default -Verbose
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
Set the Installation Policy of PSGallery
to Trusted:
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Result:
PS C:\windows\system32> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
Now you'll be able to run Update-Module
and Install-Module
successful again.
Top comments (5)
Great article, concise.
this helped me today after lot of juggling with other steps. Thank you so much..
i know it should have worked but the installation policy is still untrusted🤦♀️ any suggestions
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.