Automatic Updates using PowerShell

Automatifc Update using powershello, here is the procedure and steps to follow in case of errors.

The PowerShell command Install-WindowsUpdate -AcceptAll -AutoReboot is used to install all available Windows updates on a system, with the following options:

  • Install-WindowsUpdate: This command installs the Windows updates using the PowerShell module PSWindowsUpdate.
  • -AcceptAll: Automatically accepts all available updates, so the process doesn’t prompt the user for each update.
  • -AutoReboot: Automatically reboots the system if necessary after the updates are installed.

This is helpful for automating the installation of updates and ensuring the system restarts to apply them, without requiring manual intervention.

Running this command you could receive the following error:

The term ‘Install-WindowsUpdate’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

It means that you need to use PowerShell version 5.1 (or more) and install NuGet before running Install-WinowsUpdate

Here you can find the procedure to install PowerShell version 5.1. To install NuGet you should run the following command:

Install-PackageProvider -Name NuGet -Force

Even in this case you can receive some errors like:

  • MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
  • The request was aborted: Could not create SSL/TLS secure channel.

Verify your internet connection (or your proxy configuration) and run the following commands:

Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

The Invoke-WebRequest verifies the connection to the path where the package is stored (use the right path as options), if it fails you can have connection problem or ssl/tls problem. The secondo command is usefull to avoid ssl/tls problem.

So, after fixed these problems, here is the complete procerdure:

Install-PackageProvider -Name NuGet -Force
Install-Module -Name PSWindowsUpdate -Force
Import-Module PSWindowsUpdate
Get-Command -Module PSWindowsUpdate
Install-WindowsUpdate -AcceptAll -AutoReboot