我正在尝试使用盐堆栈运行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"):
添加
-Confirm:$false
似乎已经解决了问题。
Download_Windows_updates:
cmd.run:
- shell: powershell
- name: Download-WindowsUpdate -Download -ForceDownload -Silent -Confirm:$false