SOLVED: SIMPLE PowerShell Script To Download & Install Windows Updates Then Reboot If Necessary

I have been trying to get a simple CMD script or PowerShell or even a utility to get Windows 10 to download and install Windows Updates for about a year.  It has not gone well.

Note that Angus Briggs at PDQ support told me about a very simple PowerShell command that will kick off Windows Update and download the files, but it will not install them or check for a reboot:

(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()

Also note that following Windows Update command everyone used to use, no longer works in Windows 10:

wuauclt.exe /detectnow

So without further adieu, the SIMPLE PowerShell script that installs all of the necessary parts (except PowerShell v5 because it is built into Windows 10 1703 and newer so you likely already have it), and then downloads and installs Windows Updates, then reboots if necessary is:

# By Ian Matthews with the help of many
# Last Updated July 28 2017

# Requires PowerShell 5.0 or newer
# Apparently NUGET is required for the PSWINDOWSUPDATE module
Install-PackageProvider NuGet -Force
Import-PackageProvider NuGet -Force


# Apparentely PSWindowsUpdate module comes from the PSGallery and needs to be trusted
# See https://msdn.microsoft.com/en-us/powershell/gallery/psgallery/psgallery_gettingstarted
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted


# Now actually do the update and reboot if necessary
Install-Module PSWindowsUpdate
Get-Command –module PSWindowsUpdate
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot

This script works very well if you copy and paste it directly into a PDQ Deploy PowerShell window.

View Comments

  • Wonderful explaination from you, man. You're making it enjoyable. I cant wait to learn far more from you. That is actually a great website.

  • The clearness for your post is just cool and i can suppose you are a professional in this subject. Thank you

  • When trying to run the Add WUServiceManager -ServiceID command as above in your example I get the following error:

    Add-WUServiceManager : SATS: Unknown failure. Try debug.
    At line:1 char:1
    + Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : CloseError: (:) [Add-WUServiceManager], Exception
    + FullyQualifiedErrorId : AddService2,PSWindowsUpdate.AddWUServiceManager

Published by
Ian Matthews

This website uses cookies.