Manage Windows Update with PowerShell

< All Topics

Refer to the tutorial below on how to manage Windows Update with PowerShell to ensure that all Windows Servers are installed with latest updates

Windows Update with PowerShell – PSWindowsUpdate

Install PSWindowsUpdate Module on all Windows Servers to manage the Windows Update Client

Download and install PSWindowsUpdate on Windows Machines with PowerShell 5.1

Install-Module -Name PSWindowsUpdate

Copy the PSWindowsUpdate Module manually to PowerShell Module on Windows Machines with PowerShell 4.0

$PSv4_Path = "C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
New-Item -ItemType Directory -Path $PSv4_Path -Name "PSWindowsUpdate"

$PSWU = "C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate\\"
Copy-Item $PSWU -Recurse -Destination "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate\"

Import PSWindowsUpdate Module

#Import PSWindowsUpdate Module 
Import-Module PSWindowsUpdate 

Available Commands

Get-Command -Module PSWindowsUpdate

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Clear-WUJob                                  PSWindowsUpdate
Alias           Download-WindowsUpdate                       PSWindowsUpdate
Alias           Get-WUInstall                                PSWindowsUpdate
Alias           Get-WUList                                   PSWindowsUpdate
Alias           Hide-WindowsUpdate                           PSWindowsUpdate
Alias           Install-WindowsUpdate                        PSWindowsUpdate
Alias           Show-WindowsUpdate                           PSWindowsUpdate
Alias           UnHide-WindowsUpdate                         PSWindowsUpdate
Alias           Uninstall-WindowsUpdate                      PSWindowsUpdate
Cmdlet          Add-WUServiceManager                         PSWindowsUpdate
Cmdlet          Enable-WURemoting                            PSWindowsUpdate
Cmdlet          Get-WindowsUpdate                            PSWindowsUpdate
Cmdlet          Get-WUApiVersion                             PSWindowsUpdate
Cmdlet          Get-WUHistory                                PSWindowsUpdate
Cmdlet          Get-WUInstallerStatus                        PSWindowsUpdate
Cmdlet          Get-WUJob                                    PSWindowsUpdate
Cmdlet          Get-WULastResults                            PSWindowsUpdate
Cmdlet          Get-WURebootStatus                           PSWindowsUpdate
Cmdlet          Get-WUServiceManager                         PSWindowsUpdate
Cmdlet          Get-WUSettings                               PSWindowsUpdate
Cmdlet          Invoke-WUJob                                 PSWindowsUpdate
Cmdlet          Remove-WindowsUpdate                         PSWindowsUpdate
Cmdlet          Remove-WUServiceManager                      PSWindowsUpdate
Cmdlet          Set-PSWUSettings                             PSWindowsUpdate
Cmdlet          Set-WUSettings                               PSWindowsUpdate
Cmdlet          Update-WUModule                              PSWindowsUpdate

Version of Windows Update Client

Check the version of Windows Update Client installed


ComputerName PSWindowsUpdate PSWUModuleDll   ApiVersion WuapiDllVersion
------------ --------------- -------------   ---------- ---------------
YONG-WIN10         2.0.6995.28496  8.0        10.0.18362.387

Settings of Windows Update Client

Verify the Windows Update Client is configured to point to WSUS Server

PS C:\windows\system32\drivers\etc> Get-WUSettings

ComputerName                                 : IB-WSUS
WUServer                                     : http://IB-WSUS:8530
WUStatusServer                               : http://IB-WSUS:8530
AcceptTrustedPublisherCerts                  : 1
ElevateNonAdmins                             : 1
DoNotConnectToWindowsUpdateInternetLocations : 1
TargetGroupEnabled                           : 1
TargetGroup                                  : Servers
NoAutoUpdate                                 : 0
AUOptions                                    : 3 - Notify before installation
ScheduledInstallDay                          : 0 - Every Day
ScheduledInstallTime                         : 3
UseWUServer                                  : 1
AutoInstallMinorUpdates                      : 0
AlwaysAutoRebootAtScheduledTime              : 0
DetectionFrequencyEnabled                    : 1
DetectionFrequency                           : 22

Check Available Updates

Check available updates from WSUS Server


ComputerName Status     KB          Size Title                                                                                                                                                 
------------ ------     --          ---- -----                                                                                                                                                 
GRP-DC02     -------    KB4550970   32MB 2020-04 Security Only Quality Update for Windows Server 2012 R2 for x64-based Systems (KB4550970)

Install Updates

Install all available Windows Updates

Install-WindowsUpdate -AcceptAll

Check Update History

List the latest 5 updates installed

Get-WUHistory -Last 5 | Select Date,Title, Result

Date                  Title                                                                                          Result
----                  -----                                                                                          ------
17/4/2020 1:43:19 AM  Security Intelligence Update for Windows Defender Antivirus - KB2267602 (Version 1.313.1687.0) Succeeded
15/4/2020 8:36:07 PM  2020-04 Cumulative Update for Windows 10 Version 1909 for x64-based Systems (KB4549951)        Succeeded
15/4/2020 10:45:09 AM Security Intelligence Update for Windows Defender Antivirus - KB2267602 (Version 1.313.1554.0) Succeeded
15/4/2020 2:17:38 AM  Security Intelligence Update for Windows Defender Antivirus - KB2267602 (Version 1.313.1528.0) Succeeded
14/4/2020 12:57:13 PM Security Intelligence Update for Windows Defender Antivirus - KB2267602 (Version 1.313.1478.0) Succeeded

Status of Windows Update of Remote Computers

Generate a Report contains the most recently 5 updates installed on remote computers

$Computers = @('IB-CAS01','IB-CAS02','IB-MBX01','IB-MBX02','IB-MBXRP')

foreach ($Computer in $Computers) { 
    Get-WUHistory -ComputerName $Computer -Last 5 | Select Date, ComputerName, Result, Title | Export-Csv C:\Temp\April2020-ExchangeServers.csv -NoTypeInformation -Append } 


Check the last result


ComputerName LastSearchSuccessDate LastInstallationSuccessDate
------------ --------------------- ---------------------------
YONG-WIN10   16/4/2020 5:52:09 PM  15/4/2020 12:36:07 PM

Check whether reboot is required


ComputerName RebootRequired RebootScheduled
------------ -------------- ---------------
YONG-WIN10            False
Previous Manage Windows Firewall with PowerShell
Next Migrate FSMO Roles with PowerShell
Table of Contents