服务器操作系统: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/