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

无法在非交互模式运行PowerShell命令:PSWindowsUpdate执行问题求助

在Salt Stack中以非交互模式运行PSWindowsUpdate的Download-WindowsUpdate命令

问题描述

使用Salt Stack运行PSWindowsUpdate模块时,执行Download-WindowsUpdate命令遇到以下错误:

Download-WindowsUpdate : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.

现有Salt配置(windows_update.sls)

Install_PSWindowsUpdate:
  cmd.run:
    - shell: powershell
    - name: Install-Module -Name PSWindowsUpdate -Force

Import_PSWindowsUpdate_module:
  cmd.run:
   - shell: powershell
   - name: Import-Module PSWindowsUpdate

Download_Windows_updates:
  cmd.run:
  - shell: powershell
  - name: Download-WindowsUpdate -Download -ForceDownload -Silent 

状态运行错误输出

----------
          ID: Download_Windows_updates
    Function: cmd.run
        Name: Download-WindowsUpdate -Download -ForceDownload -Silent -Debuger
      Result: False
     Comment: Command "Download-WindowsUpdate -Download -ForceDownload -Silent " run
     Started: 02:31:11.656532
    Duration: 6433.988 ms
     Changes:
              ----------
              pid:
                  4764
              retcode:
                  1
              stderr:
                  Download-WindowsUpdate : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
                  At line:1 char:1
                  + Download-WindowsUpdate -Download -ForceDownload -Silent 
                  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      + CategoryInfo          : InvalidOperation: (:) [Get-WindowsUpdate], PSInvalidOperationException
                      + FullyQualifiedErrorId : InvalidOperation,PSWindowsUpdate.GetWindowsUpdate
              stdout:

Summary for prod1

补充信息

直接通过CMD运行该命令时,会弹出确认提示:

C:\Windows\system32>powershell.exe "Download-WindowsUpdate -Download -ForceDownload -Silent -Recurse 2"

确认
是否确实要执行此操作?
正在目标"PROD1"上执行操作"(4/3/2023 4:30:40 AM) 适用于Windows Server 2019 x64的.NET Framework 3.5、4.7.2和4.8的2023-02累积更新(KB5022782)[77MB]"。
[Y] 是  [A] 全是  [N] 否  [L] 全否  [S] 暂停  [?] 帮助 (默认值为"Y"):

解决方法

问题根源是命令需要用户确认操作,但Salt Stack运行PowerShell时处于非交互模式,无法处理这类提示。只需在Download-WindowsUpdate命令中添加-Confirm:$false参数,强制跳过所有确认步骤即可:

修改后的Download_Windows_updates状态块:

Download_Windows_updates:
  cmd.run:
  - shell: powershell
  - name: Download-WindowsUpdate -Download -ForceDownload -Silent -Confirm:$false

执行修改后的Salt状态,命令就能在非交互模式下正常下载更新,不会再触发确认提示或报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 23:02:11