Salt - 无法在非交互模式下运行 Powershell 命令

问题描述 投票:0回答:2

我正在尝试使用盐堆栈运行PSWindowsUpdate,但由于以下错误,我无法运行

Download-WindowsUpdate
命令:

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

如何使其在非交互模式下工作?

这是我的 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"

Confirm
Are you sure you want to perform this action?
Performing the operation "(4/3/2023 4:30:40 AM) 2023-02 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for
Windows Server 2019 for x64 (KB5022782)[77MB]" on target "PROD1".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
windows powershell salt windows-update
2个回答
0
投票

添加

-Confirm:$false
似乎已经解决了问题。

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

0
投票

一个查询,要执行脚本(计划为任务)并显示 powershell 窗口,我是否必须删除“-noninteractive”命令,或者是否必须添加参数来显示窗口?谢谢

© www.soinside.com 2019 - 2024. All rights reserved.