How to Install Windows Updates with PowerShell

GURU

If you only need to update one Windows system, you can use the GUI. However, if you need to update many Windows systems, it’s best to use PowerShell. Managing Windows Updates from a PowerShell window with the module PSWindowsUpdate is excellent. In this article, you will learn how to install Windows Updates with PowerShell.

Install PSWindowsUpdate module

To install PSWindowsUpdate module on your system, follow the steps below.

1. Set Windows PowerShell Execution Policy

By default, we can’t install scripts. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run PowerShell as administrator, and run the cmdlet.

Set-ExecutionPolicy RemoteSigned -Force

Important: Close and re-open the elevated Windows PowerShell window to have the changes apply.

2. Install PowerShellGet module

Run the below command to install NuGet Provider. When asked to install NuGet provider, press Y and follow with Enter.

Install-Module PowershellGet -Force

If you get an error that it’s unable to install, read the article Unable to install NuGet provider for PowerShell.

3. Install PSWindowsUpdate module

Install the PSWindowsUpdate module.

 Install-Module -Name PSWindowsUpdate -Force

Check PSWindowsUpdate commands

The PSWindowsUpdate module comes with many cmdlets and aliases. You can use these to install, uninstall, hide, and unhide Windows Updates, among other things.

To get all the cmdlets and aliases, run the command below.

Get-Command -Module PSWindowsUpdate

The below output appears.

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Clear-WUJob                                        2.2.1.5    PSWindowsUpdate
Alias           Download-WindowsUpdate                             2.2.1.5    PSWindowsUpdate
Alias           Get-WUInstall                                      2.2.1.5    PSWindowsUpdate
Alias           Get-WUList                                         2.2.1.5    PSWindowsUpdate
Alias           Hide-WindowsUpdate                                 2.2.1.5    PSWindowsUpdate
Alias           Install-WindowsUpdate                              2.2.1.5    PSWindowsUpdate
Alias           Show-WindowsUpdate                                 2.2.1.5    PSWindowsUpdate
Alias           UnHide-WindowsUpdate                               2.2.1.5    PSWindowsUpdate
Alias           Uninstall-WindowsUpdate                            2.2.1.5    PSWindowsUpdate
Cmdlet          Add-WUServiceManager                               2.2.1.5    PSWindowsUpdate
Cmdlet          Enable-WURemoting                                  2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WindowsUpdate                                  2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUApiVersion                                   2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUHistory                                      2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUInstallerStatus                              2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUJob                                          2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WULastResults                                  2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUOfflineMSU                                   2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WURebootStatus                                 2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUServiceManager                               2.2.1.5    PSWindowsUpdate
Cmdlet          Get-WUSettings                                     2.2.1.5    PSWindowsUpdate
Cmdlet          Invoke-WUJob                                       2.2.1.5    PSWindowsUpdate
Cmdlet          Remove-WindowsUpdate                               2.2.1.5    PSWindowsUpdate
Cmdlet          Remove-WUServiceManager                            2.2.1.5    PSWindowsUpdate
Cmdlet          Reset-WUComponents                                 2.2.1.5    PSWindowsUpdate
Cmdlet          Set-PSWUSettings                                   2.2.1.5    PSWindowsUpdate
Cmdlet          Set-WUSettings                                     2.2.1.5    PSWindowsUpdate
Cmdlet          Update-WUModule                                    2.2.1.5    PSWindowsUpdate

Find Windows Updates

Find available Windows Updates for the system.

Get-WindowsUpdate

Find available Windows updates on another system.

Get-WindowsUpdate -ComputerName "DC02-2022"

Find available Windows updates on multiple systems.

# List of computer names or IP addresses
$computers = @(
    "DC01-2022",
    "DC02-2022",
    "DC03-2022"
)

# Loop through each computer and execute the Get-WindowsUpdate command
foreach ($computer in $computers) {
    Get-WindowsUpdate -ComputerName $computer -AcceptAll
}

Install Windows Updates

Find available Windows Updates on the system and prompt if you are sure to install the Windows Update.

Install Windows Updates on local system

Find available Windows Updates on the local system and install them with a reboot if that’s needed.

Get-WindowsUpdate -Install

Find available Windows Updates on the system and install them without a reboot when it finishes.

Get-WindowsUpdate -AcceptAll -Install -IgnoreReboot

Find available Windows Updates on the system and install them with a reboot if that’s needed.

Get-WindowsUpdate -Install -AcceptAll -AutoReboot

Install Windows Updates on remote systems

Find available Windows Updates on multiple systems and install them with a reboot if that’s needed.

Note: You need to install the PSWindowsUpdate module on all the systems on which you want to install Windows Updates.

Fill in the computer names or the IP addresses and run the script to get and install Windows Updates on the systems.

# List of computer names or IP addresses
$computers = @(
    "DC01-2022",
    "DC02-2022",
    "DC03-2022"
)

# Loop through each computer and execute the Get-WindowsUpdate command
foreach ($computer in $computers) {
    Get-WindowsUpdate -ComputerName $computer -Install -AcceptAll -AutoReboot
}

Fill in the OU distinguished name and run the script to get and install Windows Updates on the systems.

# Specify the distinguished name of the OU
$ouDN = "OU=Computers,OU=Company,DC=exoip,DC=local"

# Get the list of computer names in the specified OU
$computers = Get-ADComputer -Filter * -SearchBase $ouDN | Select-Object -ExpandProperty Name

# Loop through each computer and execute the Get-WindowsUpdate command
foreach ($computer in $computers) {
    Get-WindowsUpdate -ComputerName $computer -Install -AcceptAll -AutoReboot
}

That’s it!

Read more: How to Install and Update PowerShell 7 »

Conclusion

You learned how to install PSWindowsUpdate module. Run Windows PowerShell 5.1 or PowerShell 7 and run the commands step by step to install the latest PSWindowsUpdate module. From now on, use the commands to install Windows Updates with PowerShell and manage everything from one window.

Did you enjoy this article? You may also like Check free disk space on Windows with PowerShell script. Don’t forget to follow us and share this article.

Share This Article
Leave a comment