System update management for Windows machines in an Active Directory (AD) environment is a critical task of an administrator. While managing the updates for a handful of machines is a fairly simple task, managing a many Windows machines and keeping track of their software updates can be cumbersome. Hence, administrators can make use of PowerShell to perform this task. Here are the scripts that can be used for deploying software updates for local and remote computers:
Deploying updates on a local computer
To deploy the updates on local computers, the following script can be used. This script will search for computers that do not have the updates installed, and then install the updates to those computers and reboot them. The script will also automatically accept any license agreements.
- Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot
Deploying updates on a remote computer
To deploy updates on remote computers, administrators must first create a variable with the names of the computers that are to be updated. Then, the following command can be typed to set the variable.
Note: $Node is the variable in this instance.
$Nodes = "computername01,computername02,....
Once done, administrators must enter the cmdlet that will import the PSWindowsUpdate module on the remote system, and then call on Microsoft Update to download and install any missing updates, and perform all the necessary actions similar to the one carried out by the script for updating local machines.
- Invoke-WUJob -ComputerName $Nodes -Script {ipmo PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot} -RunNow -Confirm:$false | Out-File "\\server\share\logs\$Nodes-$(Get-Date -f yyyy-MM-dd)-MSUpdates.log" -Force