如何使用PowerShell更新已安装的Windows?

要使用PowerShell获取已安装的Windows更新,我们可以使用Get-Hotfix命令。此命令获取本地和远程计算机上安装的修补程序和更新。

此命令是Microsoft.Management.PowerShell实用程序的一部分。

示例

Get-HotFix
输出结果
PS C:\> Get-HotFix
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
LABMACHINE... Update KB3191565 LABMACHINE2K12\Ad... 1/15/2021 12:00:00 AM
LABMACHINE... Update KB2999226 LABMACHINE2K12\Ad... 1/13/2021 12:00:00 AM

在上面的输出中,您可以看到SourceMachine名称,HotfixID,InstalledBy和安装日期。

您还可以通过InstalledOn参数对其进行排序。例如,

示例

Get-HotFix | Sort-Object InstalledOn -Descending

此命令支持ComputerName参数,它是一个字符串数组,因此我们可以传递多台远程计算机来获取已安装的修补程序。

PS C:\> help Get-HotFix -Parameter ComputerName
-ComputerName <System.String[]>
Specifies a remote computer. Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name (FQDN) of a remote computer.

例如,

示例

Get-HotFix -ComputerName LabMachine2k12,AD,LabMachine2k16