用 PowerShell 安装 Windows 更新(PSWindowsUpdate 模块)
不打开设置界面,直接命令行搜索、下载、安装更新并重启,远程会话和服务器尤其方便。
先安装 PSWindowsUpdate 模块,运行 Get-WindowsUpdate 查看待更新,再运行 Install-WindowsUpdate -AcceptAll -AutoReboot 安装并自动重启。
01命令
命令
$ Install-Module PSWindowsUpdate -Force
Get-WindowsUpdate
Install-WindowsUpdate -AcceptAll -AutoReboot02作用说明
微软没有内置更新用的 cmdlet,社区模块 PSWindowsUpdate(IT 运维常用)封装了官方 Windows Update Agent API。Get-WindowsUpdate 会列出待装更新的 KB 编号和大小;Install-WindowsUpdate 执行安装,-AutoReboot 自动处理强制重启——RDP 远程桌面里设置更新页面打不开、或无图形界面的服务器上,这一招能救命。需要管理员权限运行,首次使用要先从 PowerShell Gallery 安装模块。用 -KBArticleID KB5031234 可以只装指定补丁;想自己控制重启时间就去掉 -AutoReboot。
03风险
!注意: 这是第三方模块,务必只从官方 PowerShell Gallery 安装;用 -AcceptAll 全量安装前,先用 Get-WindowsUpdate 过一遍更新列表。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- PSWindowsUpdate依据: Module page documenting Get-WindowsUpdate and Install-WindowsUpdate cmdlets built on the Windows Update Agent API.
最后验证: 2026-09-18 · 分类: 系统与设置