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

Salt远程安装PowerShell模块PSWindowsUpdate失败求助

解决Salt远程安装PSWindowsUpdate模块的报错问题

问题重现

所有新Windows服务器通过Salt执行以下命令安装PSWindowsUpdate模块时失败:

[root@salt ~]# salt 'Windows001' psget.install PSWindowsUpdate

返回错误详情:

Windows001:
    ERROR: Issue executing powershell Install-Module -Name PSWindowsUpdate  -Force | ConvertTo-Xml -Depth 2 -As "stream". Additional info follows:

    retcode:
        1
    stderr:
        Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell处于非交互模式,读取和提示功能不可用。"
        At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7455 char:8
        +     if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ...
        +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
            + FullyQualifiedErrorId : PSInvalidOperationException

        Install-Module:与基于NuGet的仓库交互需要NuGet提供程序,请确保已安装'2.8.5.201'或更高版本的NuGet提供程序。
        At line:1 char:1
        + Install-Module -Name PSWindowsUpdate  -Force | ConvertTo-Xml -Depth 2 ...
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
            + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module
    stdout:
ERROR: Minions returned with non-zero exit code

错误原因

  1. 缺少NuGet提供程序:Install-Module依赖NuGet访问PowerShell Gallery仓库,新服务器默认未预装符合版本要求的NuGet。
  2. 旧版PowerShellGet的交互bug:1.0.0.1版本的PowerShellGet即使加了-Force参数,仍会尝试触发交互确认提示,而Salt远程执行处于非交互模式,导致报错。

解决步骤

1. 安装NuGet提供程序

通过Salt执行PowerShell命令强制安装NuGet,跳过交互:

salt 'Windows001' cmd.run "powershell -Command 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope AllUsers'"

2. 信任PowerShell Gallery仓库

默认PSGallery是未信任状态,非交互模式下安装模块会被拦截,先设置信任:

salt 'Windows001' cmd.run "powershell -Command 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'"

3. 直接安装PSWindowsUpdate模块

绕过psget.install,直接调用PowerShell命令安装,添加-SkipPublisherCheck避免交互提示:

salt 'Windows001' cmd.run "powershell -Command 'Install-Module -Name PSWindowsUpdate -Force -SkipPublisherCheck -Scope AllUsers'"

可选:升级PowerShellGet到最新版本

旧版PowerShellGet的交互bug在新版本中已修复,升级后可正常使用psget.install:

salt 'Windows001' cmd.run "powershell -Command 'Install-Module -Name PowerShellGet -Force -SkipPublisherCheck -Scope AllUsers'"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 12:23:18