derekbaker783
derekbaker783

Reputation: 9591

Powershell - Why does this module download from the Gallery fail on the server?

Server OS: Windows Server 2016 Datacenter, Build 14393
Powershell version: 5.1

I can run the code below to install a module on my laptop, but it started failing when being downloaded on a server a few days ago (It was working for a couple weeks previously in a CI/CD pipeline).

Install-Module -Name 'AzureDevOpsHelpers' -Scope CurrentUser -Force

On the server, I get the warning and error below

WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/AzureDevOpsHelpers/1.1.12' is not valid.

PackageManagement\Install-Package : Package 'AzureDevOpsHelpers' failed to download.

However, on that same server, I can manually download the package via a browser using the supposedly invalid URL above.

I found this discussion on Powershell.org, but I don't think this module is very big: https://powershell.org/forums/topic/failed-to-downloadinstall-module/

I'd like to be able to use Install-Package to install the package. Is there anything I can do aside from just hoping this will start working again?

Upvotes: 1

Views: 1277

Answers (2)

derekbaker783
derekbaker783

Reputation: 9591

If I run this in the session prior to the Install-Module command, things work as expected.

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

Upvotes: 2

Roque Sosa
Roque Sosa

Reputation: 583

Here is a something you can try:

$path = "$($env:PSModulePath.Split(';')[0])\AzureDevOpsHelpers"
if(!(Test-Path $path)){
    New-Item -Path $path -ItemType Directory | Out-Null
}
$file = "$path\package.zip"
Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/package/AzureDevOpsHelpers/1.1.12' -OutFile $file -TimeoutSec 0
Expand-Archive -Path $file -DestinationPath $path -Force
Import-Module AzureDevOpsHelpers

Results:

PS C:\WINDOWS\system32> W:\Code\Scripts\Powershell\ps1\PowerShell - Course\Solutions\StackTest3.ps1

PS C:\WINDOWS\system32> Get-Module -ListAvailable


    Directory: $env:PSModulePath\Modules


ModuleType Version    Name                                ExportedCommands                                                                                                      
---------- -------    ----                                ----------------                                                                                                      
Script     1.1.12     AzureDevOpsHelpers                  {RemoveOldCerts, _uninstallService, UpdateXmlConfigAppConnectionStringInitialCatalog, ConfigureSslForPortOnHost...}

Upvotes: 2

Related Questions