Windows

How to apply Windows Updates with PowerShell

Applying Windows Updates

Microsoft Windows provides its own patch management solution referred to as Windows Update. Having a proper grip of these updates is paramount for your production workflow as they often start automatically during business hours resulting in downtime. With PowerShell cmdlets, you can automate Windows updates, saving you effort and time. With the right patch management solution, you can enhance your system by testing or installing the latest software updates and patches. Patches are temporary fixes for existing issues between full-scale software releases. Effective patch management enables prompt vulnerability addressing and threat mitigation for your system.

However, See these guides: How to automate Windows Update with PowerShell and Task Scheduler, and how to install Microsoft PSWindowsUpdate module silently.

How to install PSWindowsUpdate

It is worth noting that PSWindowsUpdate is a third-party module that is not integrated into Windows by default. This module can be downloaded from the PowerShell gallery, the most used repository for sharing PowerShell code.

This module includes different cmdlets to manage the deployment of Windows updates from the command line. Download the PSWindowsUpdate version from the PowerShell Gallery 

Next, we will have to install the PSWindowsUpdateModule as shown below. If the PowerShell setup is already configured to allow online downloads, the PSWindowsUpdate module can also be installed directly from the online repository (PSGallery) running the command below.

 Install-Module -Name PSWindowsUpdate

Note: You may need to open an elevated PowerShell prompt and run Set-ExecutionPolicy RemoteSigned to allow the execution of scripts signed by a trusted publisher. Nonetheless, You may also want to do this via Windows Settings. However, This is because PowerShell is configured to prevent the execution of PowerShell scripts on Windows systems by default.

Updating system using PowerShell

Master how to apply Windows Updates with PowerShell for streamlined maintenance. Furthermore, Don’t miss out on optimizing your system’s performance.

Commands in PSWindowsUpdate

Installed aliases and cmdlets can be displayed by typing Get-Command–module PSWindowsUpdate.

Applying Windows Updates

A brief description of principal commands is described below:

  • Get-WindowsUpdate: At the heart of this module lies the primary cmdlet for efficient management. Nonetheless, It effortlessly compiles, downloads, and installs necessary updates, all while allowing you to define prerequisites. Plus, you can exercise control over restart protocols if you apply Windows Updates with PowerShell.
  • Remove-WindowsUpdate: Uninstalls an update.
  • Add-WUServiceManage: Registers a new Windows Update API Service Manager
  • Get-WUHistory: Shows a list of installed updates
  • Get-WUSettings: Gets Windows Update client settings
  • Get-WUInstallerStatus: Gets Windows Update Installer Status (busy or not)
  • Enable-WURemoting: Enables firewall rules for PSWindowsUpdate remoting
  • Invoke-WUJob: Invokes PSWindowsUpdate actions remotely

Install Windows Updates

For Updates directly from the Microsoft update center, use the command below.

Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
Screenshot-2022-03-23-at-21.31.03

Install Updates from WSUS

For WSUS updates, the following commands work correctly.

Get-WindowsUpdate -install -AcceptAll -AutoReboot

However, You may want to see this guide on creating a scheduled task. For Task Scheduled task error and success code, see the following link.

I trust you discovered valuable insights in this blog post about how to effectively apply Windows Updates with PowerShell. Moreover, Feel free to share your queries or thoughts in the comments section.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x