Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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.
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.
To use Install-WindowsUpdate
, you need to install the Windows Update PowerShell Module. Here’s how you can do it:
Open PowerShell as Administrator:
Win + X
and select "Windows PowerShell (Admin)" or search for PowerShell in the Start menu, right-click, and choose "Run as administrator".Install the Module:
Install-Module PSWindowsUpdate -Force
Y
and pressing Enter.Once the module is installed, you can use the Install-WindowsUpdate
cmdlet to search, download, and install updates.
To check for available updates without installing them, use the following command:
Get-WindowsUpdate
This command lists all available updates for your system.
To install all available updates, execute:
Install-WindowsUpdate -AcceptAll -AutoReboot
-AcceptAll
: Automatically accepts all updates.-AutoReboot
: Automatically reboots the system if required after installation.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.
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.
Create a PowerShell Script:
.ps1
file, for example, UpdateScript.ps1
.Schedule the Task:
powershell.exe
.-File "C:\Path\To\UpdateScript.ps1"
.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.