Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Scripts » How to automate Windows Update with PowerShell
  • Upstream branch in Git 1
    Set up and use an upstream branch in Git Version Control System
  • FileNotFoundError Errno 2 No such file or directory
    Fix FileNotFoundError: [Errno 2] No such file or directory Scripts
  • install virtualbox on linux mint ubuntu
    How to install Windows Server 2019 on Virtualbox Windows Server
  • Computer policy could not be updated
    How to fix Computer Policy could not be updated successfully Windows
  • BitLocker selfservice or helpdesk recovery
    Force BitLocker Recovery: Perform BitLocker Recovery via the Self-Service Portal and Helpdesk Network | Monitoring
  • macos12
    Enable or disable automatic login on macOS: Fix username greyed out for automatic login Mac
  • UpdateOfficeOnlineServer 1
    Perform Office Online Server Update via Windows Updates Windows Server
  • Resize Proxmox VM
    How to Resize or Expand Proxmox Hard Drive Virtualization

How to automate Windows Update with PowerShell

Posted on 24/03/202008/08/2024 Christian By Christian 2 Comments on How to automate Windows Update with PowerShell

Microsoft Windows provides its own patch management solution referred to as Windows Update. Having a proper grip on 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. In this article, we shall discuss how to automate Windows Update with PowerShell. Please see Windows 2016 Servers do not show up on the WSUS console, and how to disable automatic Windows updates.

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.

If patch management is effectively performed. You can promptly address vulnerabilities in your system and mitigate any potential threats. In this article, you will learn how to automate Windows Update with PowerShell and Task Scheduler

Kindly refer to these related guides: How to update PowerShellGet and Package Management, how to install and update PowerShell version 7 on Windows and Linux, and Important Areas to Master on WSUS.

Automate Windows Update with PowerShell

In order to orchestrate Windows Update with PowerShell, the module “PSWindowsUpdate” needs to be installed. This module contains cmdlets to manage the Windows Update Client (servers). This module is vital because it helps automate the deployment of Windows Update using the

  • “Invoke-WUInstall” command to install Windows Updates remotely on computers or with the following below that can be configured via task scheduler to automate updates on individual computers.
  • “Install-WindowsUpdate” for installing updates from the Microsoft Update Center or with the – “Get-WindowsUpdate” to update Windows from WSUS.

Please, see how to Configure WSUS Email Notification to Work With Office365, Configuring WSUS Email Notification to Work With Office365 â€“ IIS SMTP Relay Server and how to configure SSL between WSUS servers (Upstream and Downstream Servers).

More on PSWindowsUpdate

To make the Windows patch management process smooth and easy as discussed above, you can use the PSWindowsUpdate module. This module is publicly available and can be downloaded for free from the PowerShell Gallery. The main requirement is that a computer needs to run Windows OS versions starting from Vista or Windows Server 2008. Also, you need to have PowerShell 2.0 or later.

With PSWindowsUpdate, you can identify if any Windows updates are available for your computer. Moreover, this module allows you to centrally manage Windows updates across various Windows servers and workstations.

This way, you can remotely control which updates are installed, removed, or hidden.

You might be interested in these: WSUS Setup: How to configure Windows server update services, and how to target WSUS clients with the registry keys.

Download the PSWindowsUpdateModule

Note: This module is not installed by default on Windows Servers. When installed it contains a set of functions to check, download and install updates from PowerShell. First, download the PSWindowsUpdateModule:

Screenshot-2022-03-23-at-20.56.02

Copy the following command below

Screenshot-2022-03-23-at-20.57.54

Install the PSWindowsUpdateModule

Next, install the PSWindowsUpdateModule. To have the module installed in PowerShell 5 and above, use the cmdlets below. Take a look at “Handy WSUS Commands: Windows Server Update Services Commands, WAUACLT, PowerShell and USOClient” as well.

Install-Module PSWindowsUpdate

Note: To automate this installation in an unattended (silent) mode, use the command by adding the “-Force” flag as shown below

Install-Module PSWindowsUpdate -Force
Screenshot-2022-03-23-at-21.03.36

To list all the modules installed, use the command below

Get-Command –module PSWindowsUpdate
module-PSWindowsUpdate

Next, run the command below. If the updates are not already downloaded. The command will contact the WSUS and pull the updates, have the updates installed and restart the server.

Here is the meaning of the command.

Get-WUInstall, Install-WindowsUpdate (alias for Get-WindowsUpdate –Install) – install updates

Please see Unattended mode: How to install the Microsoft PSWindowsUpdate module silently, and how to fix “The VM appears to be in use: Taking ownership failed“

Install Microsoft Updates

For Updates directly from the Microsoft update centre, use the command below. The command below might not work correctly, because of this, the “install-WindowsUpdate” is my desired choice.

Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot
Install-WindowsUpdate-MicrosoftUpdate-AcceptAll-AutoReboot
Applying-updates

For Updates directly from the Microsoft update centre. Use this command below as this is proven to work!

Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot
Get-WUInstall-–MicrosoftUpdate-–AcceptAll-–AutoReboot

To have this run at a specific period of time, create a PowerShell script and create a scheduled task to automate Windows Update with the code below.

Install-Module PSWindowsUpdate -Force
#installs everything (newest version) along with required modules.
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot
#Will ensure that updates are downloaded, installed completely and then restarted.

The AcceptAll key accepts the installation of all update packages, and AutoReboot allows Windows to automatically restart after the updates are installed.

WSUS Updates (Windows Server Update Services)

For WSUS updates, the following commands work correctly.

Get-WindowsUpdate -install -AcceptAll -AutoReboot

Next steps! Have your script automated. See the steps to create a scheduled task. Also, see some details on Task Scheduled task error and success code

I hope you found this blog post helpful on How to Automate Windows Update with PowerShell. Now, you have learned how to automate Windows Update with PowerShell and Task Scheduler. If you have any questions, please let me know in the comment session.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Scripts Tags:Microsoft Windows, PowerShell, Task Scheduler, Windows 10, Windows 11, Windows Server 2016, Windows Update

Post navigation

Previous Post: All Task Scheduler Errors and Success Codes
Next Post: Cannot find the computer: Fix the following error occurred while using Kerberos authentication

Related Posts

  • Microsoft Defender
    Attack Surface Reduction Configuration with Microsoft Defender Scripts
  • Generate SSH Keys
    Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
  • windows powershell thumbnail
    Unable to uninstall AppX? How to uninstall builtin programs using PowerShell in Windows 10 Scripts
  • image 130
    How to fix the Security Database on the Server does not have a Computer Account for this Workstation Trust Relationship on Windows Server [Part 2] Scripts
  • 7164 1024x575 1
    How to install MDT PowerShell module on Windows Scripts
  • FileNotFoundError Errno 2 No such file or directory
    Fix FileNotFoundError: [Errno 2] No such file or directory Scripts

More Related Articles

Microsoft Defender Attack Surface Reduction Configuration with Microsoft Defender Scripts
Generate SSH Keys Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
windows powershell thumbnail Unable to uninstall AppX? How to uninstall builtin programs using PowerShell in Windows 10 Scripts
image 130 How to fix the Security Database on the Server does not have a Computer Account for this Workstation Trust Relationship on Windows Server [Part 2] Scripts
7164 1024x575 1 How to install MDT PowerShell module on Windows Scripts
FileNotFoundError Errno 2 No such file or directory Fix FileNotFoundError: [Errno 2] No such file or directory Scripts

Comments (2) on “How to automate Windows Update with PowerShell”

  1. Avatar photo Sunil says:
    07/03/2022 at 10:15 PM

    Thanks for the detailed steps. I tried the steps you’ve outlined above and all works well when you open Powershell in Administrator mode and run it manually.

    For example, I had 2 updates to be installed and when I ran the command “Get-WindowsUpdate -install -AcceptAll -AutoReboot” in the powershell window, I saw it download and update and reboot the server. This took approximately 16 mins.

    But when trying to run it via scheduled task, I go back in and check 30 mins later, the scheduled tasks status shows ‘running’ and doesn’t reboot the host. Any suggestions on what I’m doing wrong?

    Log in to Reply
    1. chris Christian says:
      12/03/2022 at 7:48 AM

      You are welcome! Please take a look at this guide: https://techdirectarchive.com/2020/03/24/how-to-create-a-scheduled-task-on-windows-server-2019/

      Also, ensure on this PC, you have the execution policy set!

      • https://techdirectarchive.com/2020/02/04/how-to-set-execution-policy/
      • https://techdirectarchive.com/2021/02/12/how-to-determine-which-execution-policy-is-configured-on-your-windows-device/

      If you are still having issues, please let me know.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • Upstream branch in Git 1
    Set up and use an upstream branch in Git Version Control System
  • FileNotFoundError Errno 2 No such file or directory
    Fix FileNotFoundError: [Errno 2] No such file or directory Scripts
  • install virtualbox on linux mint ubuntu
    How to install Windows Server 2019 on Virtualbox Windows Server
  • Computer policy could not be updated
    How to fix Computer Policy could not be updated successfully Windows
  • BitLocker selfservice or helpdesk recovery
    Force BitLocker Recovery: Perform BitLocker Recovery via the Self-Service Portal and Helpdesk Network | Monitoring
  • macos12
    Enable or disable automatic login on macOS: Fix username greyed out for automatic login Mac
  • UpdateOfficeOnlineServer 1
    Perform Office Online Server Update via Windows Updates Windows Server
  • Resize Proxmox VM
    How to Resize or Expand Proxmox Hard Drive Virtualization

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,834 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

Active Directory AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.