Use PowerShell to install Windows Updates

PowerShell for Windows updates? Why would you want to do this other than the fact that it’s a cool thing to do? Well it’s fairly easy to do and can be easilly automated.

Firstly you will need version 5 of PowerShell which is apart of Windows 10. Since version 5 you can now download and install modules online from the PowerShell Gallery.

First thing you need to do is confirm the version of PowerShell you have:

$PSVersionTable.PSVersion

If version 5 or above, confirm you are running PowerShell as administrator and continue with:

Install-Module PSWindowsUpdate
Get-Command –module PSWindowsUpdate

Then you will need to register to use the Microsoft Update Service not just the default Windows Update Service.

Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d

Then run:

Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot

More info here: https://www.petri.com/manage-windows-updates-with-powershell-module

PowerShell

6 Comments Leave a comment

  1. I realize this was posted 10 months ago (and thank you for the article) but, has anyone managed to set this is as a scheduled task for automating windows updates? I can run it manually without issue but there seems to be some issue in calling on it to run without a logged on user through task scheduler. Any input would be greatly appreciated.

    Thanks!

    • I realize this is an old post but this is for the benefit of anyone else looking to do the same thing.
      For PowerShell scripts that you wish to run non-interactively (without a user logged in) such as startup scripts or those executed from Task Scheduler, Make sure to check the following:
      1. Ensure that the executionpolicy allows the execution of the script as the user that will execute the script (for startup scripts that user is SYSTEM).
      2. The user has “Log on as a Service” rights on the PC where the script will be executing. (this can be set through local security policy or group policy)
      3. For Task Scheduler Tasks:
      -check the box on the task in Task Scheduler to “Run whether the user is logged on or not.”,
      -for tasks which require elevation, such as updating Windows and scripts that call “Install-Module”, make sure that user is a local administrator and check the box on the task that says “run with highest privileges.”

  2. In the latest version of PSWindowsUpdate the update command must include -Install, making the correct command look like this:
    Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot -Install
    Without the -Install parameter, the command just lists the packages.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: