Wednesday 27 March 2024

Resolving PowerShell Module Installation Error


When installing a PowerShell module, you may encounter the following error:

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'

This error can occur due to various reasons, but one common cause is related to the Transport Layer Security (TLS) version that your PowerShell system is using.

The Role of TLS

The PowerShell Gallery, where PowerShell modules are hosted, only accepts connections using TLS 1.2 or later. If your system is using an older version of TLS, it may fail to establish a connection with the PowerShell Gallery, resulting in the error mentioned above.

The Solution

To resolve this issue, you need to force your PowerShell system to use TLS 1.2. This can be achieved by running the following command in your PowerShell session:

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

This command sets the security protocol of your PowerShell session to TLS 1.2. After running this command, you should be able to install the PowerShell module without encountering the error.

Please note that this change will only apply to the current PowerShell session. If you start a new session, you will need to run the command again.

No comments:

Post a Comment