PowerShell disabled support for TLS 1.0 for the Gallery - Update-Module and Install-Module broken
Tags: powershell
Published: 2020-05-14 08:56:26

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](https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/).

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](https://dev-to-uploads.s3.amazonaws.com/i/d5szocibslnmo5ua4kag.png)

![PowerShell Gallery currently unavailable](https://dev-to-uploads.s3.amazonaws.com/i/5ctoon8ucebwmhroa99e.png)

```ps
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
........... (cutted)
```

```ps
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:

```ps
[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:
```ps
[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:
```ps
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
```
Now register the `PSGallery` again:
```ps
Register-PSRepository -Default -Verbose
```
Check the success with `Get-PSRepository` and you should see an output like this:

```ps
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*:
```ps
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
```

Result:
```ps
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.