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 Get-WindowsUpdate in Windows PowerShell to Manage Updates

Managing updates on Windows systems is crucial for maintaining security and performance. One of the most powerful tools for handling updates is PowerShell, specifically using the Get-WindowsUpdate cmdlet. This article will guide you through the process of using Get-WindowsUpdate to check for, download, and install updates on Windows.

Understanding Get-WindowsUpdate

Get-WindowsUpdate is a cmdlet provided by the Windows Update PowerShell Module (PSWindowsUpdate). This module allows administrators to manage Windows updates from the command line, offering greater flexibility and automation capabilities compared to the traditional GUI-based Windows Update interface.

Installing the PSWindowsUpdate Module

Before you can use Get-WindowsUpdate, you need to install the PSWindowsUpdate module. Here’s how you can do it:

  1. Open PowerShell as an Administrator.

  2. Run the following command to install the module from the PowerShell Gallery:

    Install-Module -Name PSWindowsUpdate -Force -Scope CurrentUser
  3. Import the module into your PowerShell session:

    Import-Module PSWindowsUpdate

Checking for Updates

To check for available updates, you can use the Get-WindowsUpdate cmdlet:

Get-WindowsUpdate

This command will list all available updates for your system.

Downloading and Installing Updates

To download and install updates, use the Install-WindowsUpdate cmdlet. You can specify which updates to install or choose to install all available updates.

  1. To install all available updates:

    Install-WindowsUpdate -AcceptAll -AutoReboot
    • -AcceptAll: Automatically accept all updates.
    • -AutoReboot: Automatically reboot the system if required after installation.
  2. To install specific updates, you can use the -KBArticleID parameter:

    Install-WindowsUpdate -KBArticleID KB5005565 -AcceptAll -AutoReboot

Scheduling Updates

You can schedule updates to run at a specific time using Task Scheduler and PowerShell. Here’s an example of how to create a scheduled task to run the update script daily at 3 AM:

  1. Create a PowerShell script (e.g., UpdateScript.ps1) with the following content:

    Import-Module PSWindowsUpdate
    Install-WindowsUpdate -AcceptAll -AutoReboot
  2. Open Task Scheduler and create a new task.

  3. Configure the task to run daily at 3 AM.

  4. Set the action to start a program and specify powershell.exe as the program.

  5. Add the following arguments to run your script:

    -File "C:\Path\To\Your\Script\UpdateScript.ps1"

Conclusion

Using Get-WindowsUpdate and the PSWindowsUpdate module in PowerShell provides a powerful way to manage Windows updates. Whether you need to check for, download, install, or schedule updates, these cmdlets offer a flexible and automated approach to keeping your systems up-to-date.

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.