Powershell - 为什么从库中下载此模块在服务器上失败?

标签 powershell

服务器操作系统:Windows Server 2016 数据中心,内部版本 14393

Powershell 版本:5.1

我可以运行下面的代码在我的笔记本电脑上安装一个模块,但是几天前在服务器上下载时它开始失败(它在 CI/CD 管道中工作了几周)。

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

在服务器上,我收到以下警告和错误
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.

但是,在同一台服务器上,我可以使用上面假定的无效 URL 通过浏览器手动下载包。

我在 Powershell.org 上找到了这个讨论,但我认为这个模块不是很大:https://powershell.org/forums/topic/failed-to-downloadinstall-module/

我希望能够使用 Install-Package 来安装软件包。除了希望这会再次开始工作之外,我还能做些什么吗?

最佳答案

您可以尝试以下方法:

$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

结果:
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...}

关于Powershell - 为什么从库中下载此模块在服务器上失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61065132/

相关文章:

powershell - 发送多行正文和多个附件

powershell - 使用 PowerShell,如何让 Write-Debug 输出显示在控制台中?

powershell - 如何在 PowerShell 中比较两个表的一列略有不同?

powershell - 在 PowerShell 输出文件中使用上个月的名称

powershell - PowerShell和交互式外部程序

powershell - 脚本未从文本文件中选取所有服务器

powershell - 如何将字符串作为非字符串传递给 powershell 中的命令?

powershell - 在PowerShell中的mshtml.HTMLDocumentClass对象上使用querySelectorAll会导致崩溃

powershell - 如何使用 PSCustomObjects 对对象进行不可变的更改?

python - 创建 Windows 10 桌面快捷方式以在 venv 虚拟环境中运行 python 脚本