Install-Module Notes

Recently I noticed I wasn’t able to install any module from the PowerShell repositories I had, but through the browser the download succeeded. I ran the -debug parameter, detailing that the cmdlet had no issue accessing the repository site or path either, just saying 'failed to download' at the end.

It was rather odd; I even re-adding a copy the default PSGallery thinking that it was somehow corrupted didn't help:

Set-PSRepository -Name "PSGallery1" -SourceLocation ""  -InstallationPolicy Trusted

I listed the current repositories I had and tried to install a module again:

Install-Module -Name PSWindowsUpdate -Repository "PSGallery1"

Still no dice. I did some more reading into this issue and discovered TLS 1.2 needed to be set within this PowerShell session:

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

After running this command, Install-Module suceeded. To make this persistent, you need to create and modify your PowerShell profile to include it. To check whether you have a PowerShell Profile:

Test-Path $profile

If the returned value is $false, you will need to create a blank profile yourself:

New-Item -Path $profile -type file –Force

Now edit the profile file to include enabling TLS 1.2 or other options:

notepad C:\Users\MyAccount\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

In my example, I changed the default path along with enabling TLS 1.2 and clearing the session:

Set-Location C:\

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