用 PowerShell 安装 Windows 更新(PSWindowsUpdate 模块)

不打开设置界面,直接命令行搜索、下载、安装更新并重启,远程会话和服务器尤其方便。

Windows更新重启PowerShell中风险
先安装 PSWindowsUpdate 模块,运行 Get-WindowsUpdate 查看待更新,再运行 Install-WindowsUpdate -AcceptAll -AutoReboot 安装并自动重启。

01命令

命令
$ Install-Module PSWindowsUpdate -Force
Get-WindowsUpdate
Install-WindowsUpdate -AcceptAll -AutoReboot

02作用说明

微软没有内置更新用的 cmdlet,社区模块 PSWindowsUpdate(IT 运维常用)封装了官方 Windows Update Agent API。Get-WindowsUpdate 会列出待装更新的 KB 编号和大小;Install-WindowsUpdate 执行安装,-AutoReboot 自动处理强制重启——RDP 远程桌面里设置更新页面打不开、或无图形界面的服务器上,这一招能救命。需要管理员权限运行,首次使用要先从 PowerShell Gallery 安装模块。用 -KBArticleID KB5031234 可以只装指定补丁;想自己控制重启时间就去掉 -AutoReboot。

03风险

风险中风险
使用条件PowerShell as Administrator; internet access to the PowerShell Gallery and Microsoft Update
!注意: 这是第三方模块,务必只从官方 PowerShell Gallery 安装;用 -AcceptAll 全量安装前,先用 Get-WindowsUpdate 过一遍更新列表。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • PSWindowsUpdate
    PowerShell Gallery · community · 2026-09-17
    依据: Module page documenting Get-WindowsUpdate and Install-WindowsUpdate cmdlets built on the Windows Update Agent API.

最后验证: 2026-09-18 · 分类: 系统与设置

06相关方案