You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Server 2016虚拟机安装SqlServerDSC模块遇NuGet错误求助

解决Server 2016上Install-Module安装SqlServerDsc时的NuGet提供者问题

步骤1:强制启用TLS 1.2并手动安装NuGet提供者

Server 2016默认TLS版本可能不足以连接PowerShell Gallery,先更新TLS设置再手动安装指定版本的NuGet:

  • 执行命令设置TLS 1.2:
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    
  • 安装最低要求版本的NuGet提供者:
    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
    
  • 若上述命令仍失败,可手动下载NuGet.2.8.5.201.nupkg文件到本地路径(如C:\Temp),再执行本地安装:
    Install-PackageProvider -Name NuGet -Source C:\Temp -Force
    

步骤2:确保PowerShell Gallery被信任

未信任的PSRepository会导致下载失败,检查并设置信任:

  • 查看当前仓库状态:
    Get-PSRepository
    
  • 若PSGallery的InstallationPolicy为Untrusted,设置为信任:
    Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
    

步骤3:排查代理设置(即使网络连通也需确认)

PowerShell可能单独使用代理设置,导致无法访问NuGet源:

  • 查看系统代理设置:
    Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
    
  • 若存在代理,临时禁用后重试安装:
    [System.Net.WebRequest]::DefaultWebProxy = $null
    

步骤4:重置NuGet模块缓存

旧缓存可能导致冲突,清除后重新安装:

Remove-Item -Path "$env:ProgramFiles\WindowsPowerShell\Modules\NuGet" -Recurse -Force -ErrorAction SilentlyContinue

完成以上步骤后,重新执行Install-Module -Name SqlServerDsc即可。

内容的提问来源于stack exchange,提问作者Marwan Takchi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 12:15:07