Powershell

How to use PowerShell to manage Windows Update

You can use the Windows Update tool to keep your system updated with the most recent security fixes and enhancements. However, you may sometimes want to have more control over how and when Windows Update runs on your computer. For example, you may want to manually check for updates, install only certain updates, or schedule updates to run at a convenient time.

How to use PowerShell to manage Windows Update

To use PowerShell to manage Windows Update third-party module called PSWindowsUpdate is normally used. With the help of the PSWindowsUpdate module, you may use PowerShell to customize Windows Update in Windows. It provides more functionality and flexibility than the built-in Windows Update settings, such as listing, installing, hiding, viewing, and scheduling updates. You must install the PSWindowsUpdate module from the PowerShell Gallery in order to utilize it. To accomplish this, run the following command:

Install-Module -Name PSWindowsUpdate -Force

 

Run the following command to view the PSWindowsUpdate module’s available cmdlets:

Get-Command -Module PSWindowsUpdate

 

Check for Available Windows Updates with PowerShell

Use the Get-WindowsUpdate or Get-WUList cmdlet to see if any updates are currently available for your PC before installing Windows updates using PowerShell:

Get-WindowsUpdate

 

This command will return a list of updates that apply to your device. You can also use filters to search for updates in specific categories, such as software or security. For example:

Get-WindowsUpdate -Category Software

 

This command will return only software updates but here in the above image I do not have one so the command is not showing any.

Installing Available Windows Updates with PowerShell

PowerShell may now be used to automatically download and install all Windows updates from the Windows Update servers and for that execute:

Get-WindowsUpdate -AcceptAll -Install -AutoReboot

 

These commands will download and install all the updates that apply to your device and automatically reboot the computer to apply the changes.

Installing Specific Windows Updates with PowerShell

Instead of installing all of the Windows’s updates, you might wish to do so occasionally. In this case, you can use the -KBArticleID parameter to specify the KB information of the update you want to install.This is useful in the case if you have missed any of the security update then you can get the knowledge base (KB) ID from the Microsoft catalog and then use the below syntax:

Get-WindowsUpdate -Install -KBArticleID <ID-number>>

 

Viewing the Windows Update History with PowerShell

You might want to use PowerShell to view the history of Windows updates and the Get-WUHistory cmdlet can be used to accomplish this:

Get-WUHistory

 

This command will return a list of updates that were installed on your device previously, along with their status, date, and source.

Removing Specific Windows Updates with PowerShell

In some cases, faults or troubles may make you decide to uninstall previously applied Windows updates. The uninstall-WindowsUpdate cmdlet can be used in this situation, and you can give the KB information of the update you want to uninstall. For example:

Remove-WindowsUpdate -KBArticleID <ID-number> -IgnoreReboot

 

This command will remove the update with the KB number KB without restarting the computer.

Additionally, you can prevent the Windows Update servers from installing a particular Windows update on your machine by hiding it. The following commands, for instance, can be used to hide the KB5005565 update.

$Hidelist = "KB5005565"
Get-WindowsUpdate -KBArticleID $HideList -Hide

 

Conclusion

To use PowerShell to manage Windows Update use the PSWindowsUpdate module. Through this module you can perform common tasks with Windows Update, such as checking, installing, hiding, viewing, and removing updates. You can use PowerShell to manage Windows Update more efficiently and effectively than using the graphical user interface.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.