Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Use Install-WindowsUpdate in PowerShell to Manage Windows Updates

Windows updates are crucial for maintaining the security and performance of your system. While the Windows Update GUI is user-friendly, there are scenarios where you might need to manage updates programmatically, such as in automated scripts or remote management tasks. PowerShell provides a versatile command-line interface to perform these tasks efficiently. In this article, we'll explore how to use the Install-WindowsUpdate cmdlet to manage updates on Windows systems.

Understanding Install-WindowsUpdate

The Install-WindowsUpdate cmdlet is part of the Windows Update PowerShell Module, which allows you to manage Windows updates directly from the command line. This module is not included by default in Windows PowerShell, so you'll need to install it first.

Installing the Windows Update Module

To use Install-WindowsUpdate, you need to install the Windows Update PowerShell Module. Here’s how you can do it:

  1. Open PowerShell as Administrator:

    • Press Win + X and select "Windows PowerShell (Admin)" or search for PowerShell in the Start menu, right-click, and choose "Run as administrator".
  2. Install the Module:

    • Run the following command to install the module from the PowerShell Gallery:
      Install-Module PSWindowsUpdate -Force
    • You might be prompted to install the NuGet provider. Confirm by typing Y and pressing Enter.

Using Install-WindowsUpdate

Once the module is installed, you can use the Install-WindowsUpdate cmdlet to search, download, and install updates.

Example: Checking for Updates

To check for available updates without installing them, use the following command:

Get-WindowsUpdate

This command lists all available updates for your system.

Example: Installing Updates

To install all available updates, execute:

Install-WindowsUpdate -AcceptAll -AutoReboot
  • -AcceptAll: Automatically accepts all updates.
  • -AutoReboot: Automatically reboots the system if required after installation.

Example: Excluding Specific Updates

If you want to exclude certain updates, you can use the -NotKBArticle parameter:

Install-WindowsUpdate -AcceptAll -AutoReboot -NotKBArticle "KB1234567"

Replace "KB1234567" with the KB number of the update you wish to exclude.

Scheduling Updates

You can schedule updates using Task Scheduler to run the PowerShell script at specific times. This is useful for automating updates during non-working hours.

  1. Create a PowerShell Script:

    • Save your update commands in a .ps1 file, for example, UpdateScript.ps1.
  2. Schedule the Task:

    • Open Task Scheduler and create a new task.
    • Set the trigger to your desired schedule.
    • In the "Action" tab, set the action to "Start a program" and point it to powershell.exe.
    • In the "Add arguments" field, enter -File "C:\Path\To\UpdateScript.ps1".

Conclusion

Using the Install-WindowsUpdate cmdlet in PowerShell provides a powerful way to manage Windows updates, especially for systems administrators and advanced users who require automation and scripting capabilities. By integrating these commands into scripts and scheduled tasks, you can ensure your systems remain up-to-date with minimal manual intervention.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.