Close

Not a member yet? Register now and get started.

lock and key

Sign in to your account.

Account Login

Forgot your password?

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:windows-update-script-download-install-reboot

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.

Share This With Your Friends Now:
Facebooktwittergoogle_plusredditpinterestlinkedin

Leave a Reply