update and restart from powershell or command line

Erwin Pauwels 10 Reputation points
2024-03-11T11:55:06.7966667+00:00

Dear all,

I've been looking for a solution on how to install feature updates from the command line or Powershell in windows 10/11.

I've already found the get-windowsupdate PS feature, this also reboots after installing windows updates, but for some reason feature updates (for example the 22h2 version update) isn't installed.

Also tried Usuclient RestartDevice or wuaclt doesn't seem to do much.

The only way to have the update installed is by physically connect to the device and click the button in windows updates "Reboot Now".

I'm basically looking for the code which triggers the "Reboot Now" in windows update so I can add this to my script/

thank you all.

Erwin

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,159 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,930 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,309 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Dominique Schluep 320 Reputation points
    2024-03-11T14:31:11.7133333+00:00

    Hello Erwin Pauwels

    Here are the commands for PSWindowsUpdate with PowerShell:

    # Install the Windows Update module
    Install-Module -Name PSWindowsUpdate -Force
    
    # Import the Windows Update module
    Import-Module PSWindowsUpdate
    
    # Check for updates
    Get-WindowsUpdate -AcceptAll -Install -AutoReboot
    
    # Restart the system if updates require a reboot
    Restart-Computer -Force
    
    1 person found this answer helpful.

  2. CARLOS VICTORINO 21 Reputation points
    2024-03-21T17:16:34.0966667+00:00

    Edwin,

    Take a look at these

    https://dennisbabkin.com/blog/?t=how-to-enable-installation-of-updates-or-to-prevent-it-during-reboot-or-shutdown

    https://community.spiceworks.com/t/programatically-rebooting-windows-and-applying-a-windows-10-feature-update/681628

    This is what worked for me:

    $WshShell = New-Object -comObject WScript. Shell $WshShell.RegWrite('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Orchestrator\InstallAtShutdown', '1', 'REG_DWORD')

    Restart-Computer