Windows 10 Powershell is a very powerful command-line tool.
With the latter, you can very easily download and install Windows Update.
This goes even further because you can control Windows Update such as restart expectations to install the updates.
This article gives you most of the Powershell commands and cmdlets to download and install Windows Update updates.
Contents
Introduction
There are two solutions for finding and installing PowerShell updates:
- WindowsUpdateProvider: This group of cmdlets is included by default in Windows 10 and Windows Server 2018.
- PSWindowsUpdate: Additional module which offers additional functionalities such as listing the update history.
This article details these two groups of Powershell commands.
To list and display the latest updates installed, the command to use is:
gwmi win32_quickfixengineering |sort installedon -desc
WindowsUpdateProvider
Here is the list of available commands:
- Start-WUScan: Check for available updates.
- Install-WUUpdates: Download and install updates.
- Get-WUIsPendingReboot: Indicates if an update is waiting to install at the next reboot. It returns true in this case.
- Get-WULastInstallationDate: Returns the date of the last installation of an update.
- Get-WULastScanSuccessDate: Returns the date of the last successful Windows Update verification.
- Get-WUAVersion: Returns the version of the Windows Update client.
Check for updates
The Start-WuScan command is used to check for updates.
If you do not specify any parameters, all updates that apply to the system will appear in the results.
To filter on software updates:
Start-WUScan -SearchCriteria "Type='Software' AND IsInstalled=0"
But it can work on a remote computer.
$u = Invoke-Command -ComputerName MonPC -ScriptBlock {Start-WUScan -SearchCriteria "UpdateId='' AND IsInstalled=1"} -Credential administrateuradmin
$ u then contains the list of available updates.
Install updates
Then we use the Powershell command Install-WUUpdates to install the update.
Then to install the pending updates.
$Updates = Start-WUScan
Write-Host "Updates Found: " $Updates.Count
Install-WUUpdates -Updates $Updates
Finally, the command to update a remote PC:
$cs = New-CimSession -ComputerName MonPc -Credential Credential admin admin
Install-WUUpdates -Updates $u -CimSession $cs
The parameter -DownloadOnly allows you to download the update without installing it.
Windows Update PowerShell Module
Installation
By default PowerShell does not allow you to control Windows Update.
But we can extend these functions by installing the Windows Update PowerShell Module.
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Import-Module PSWindowsUpdate
Powershell Command-List
Here are the Powershell cmdlets available to control Windows Update:
- Download-WindowsUpdate (aka Get-WindowsUpdate -Download) : Download updates
- Get-WUList: Get a list of available updates that meet certain criteria.
- Get-WUInstall, Install-WindowsUpdate: Download and install updates.
- Add-WUOfflineSync: Save the scanner service offline
- Get-WUServiceManager: Display the configuration of the Service Manager.
- Get-WUHistory: Get a list of previous updates.
- Get-WUInstallerStatus: Check the status of the Windows Update installer.
- Get-WURebootStatus: Check the restart status of Windows Update and offers to restart the PC.
- Get-WUUninstall: Uninstall the update.
- Hide-WindowsUpdate (alias Get-WindowsUpdate -Hide: $ false): hide an update.
- Remove-WUOfflineSync: Unregister the offline scanner service.
Check for updates
Here is the Powershell command to list the Windows Update updates awaiting installation:
Get-WUlist
And to list the updates from a remote PC:
Get-WUList -ComputerName NomDeLaMachine
Install updates
Here is the command to install all the updates:
Install-WindowsUpdate -AcceptAll
And to force the restart:
Install-WindowsUpdate -AcceptAll -AutoReboot
But also to install specific updates in PowerShell:
Get-WindowsUpdate -KBArticleID KB2267602, KB4533002 -Install
And finally to exclude updates, here is the PowerShell command:
Install-WindowsUpdate -NotCategory "Drivers" -NotTitle OneDrive -NotKBArticleID KB4011670 -AcceptAll -IgnoreReboot
Install an update on a remote PC
And if you want to install Windows Update updates by PowerShell on remote PCs:
$Serveurs= "serveur1, serveur2, serveur3"
Invoke-WUJob -ComputerName $ServerNames -Script {ipmo PSWindowsUpdate; Install-WindowsUpdate -AcceptAll | Out-File C:WindowsPSWindowsUpdate.log } -RunNow -Confirm:$false
Block and Hide an update
$HideList = "KB4489873", "KB4489243"
Get-WindowsUpdate -KBArticleID $HideList –Hide
Finally to list the hidden updates:
Get-WindowsUpdate –IsHidden
Finally to unlock updates, here are two different Powershell commands:
Get-WindowsUpdate -KBArticleID $HideList -WithHidden -Hide:$false
Show-WindowsUpdate -KBArticleID $HideList
Uninstall an update
To uninstall an update with PowerShell, we use Get-WUUninstall:
Get-WUUninstall -KBArticleID KBXXX