Windows updates come with their fair share of drama, don't they? Whether you're in the middle of drafting a critical email or finally defeating that level in a game you've been stuck on, updates swoop in unannounced, like an unwelcome visitor. As irritating as these interruptions can be, let's give credit where credit is due—Windows updates are essential for keeping your PC secure and running smoothly.
The good news? You no longer have to let updates control your day. By leveraging PowerShell with a dash of administrative magic, you can automate the entire Windows update process. And before you ask—no, you don't need wizard-level tech skills to pull this off. Let’s dive in, step-by-step, and get you ahead of Windows Update’s antics.
Once enabled, modify the script to target additional machines:
0
Source: XDA Tired of dealing with Windows updates? Here's how to automate them with PowerShell
The good news? You no longer have to let updates control your day. By leveraging PowerShell with a dash of administrative magic, you can automate the entire Windows update process. And before you ask—no, you don't need wizard-level tech skills to pull this off. Let’s dive in, step-by-step, and get you ahead of Windows Update’s antics.
Setting the Scene: What You'll Need
Tools for the Job:
- PowerShell: Pre-installed on all modern versions of Windows (10 and 11).
- PSWindowsUpdate Module: A powerful add-on that enables smooth management of updates.
- Administrative Privileges: Yes, you'll need God-mode level access on your PC.
- A user account with admin rights.
- Your nerves—you’re about to take charge of your updates like a tech-savvy boss.
Step-by-Step Guide: Automating Updates with PowerShell
While “automation” sounds complex, the process is surprisingly straightforward. Let me show you the magic in three quick acts: Setting Up, Writing the Script, and Automating the Script.Step 1: Installing the PSWindowsUpdate Module
Think of PSWindowsUpdate as the bridge between chaotic interruptions and serene automation. But first, you need to install it:- Open PowerShell as an Administrator:
- Search for "PowerShell" in the Start menu, then right-click and select Run as administrator.
- Run this command to install the module:
Code:Install-Module PSWindowsUpdate
- When prompted, press
Y
to confirm installation of the NuGet provider (if necessary) andA
to accept all conditions. - Import the module into PowerShell:
Code:Import-Module PSWindowsUpdate
- If you run into trust issues (literally, PowerShell will tell you), solve them by adjusting the execution policy:
Code:Set-ExecutionPolicy Unrestricted
- Rerun the
Import-Module
command, and it should work like a charm.
Step 2: Crafting the Automation Script
Scripts are the heart and soul of automation. Let’s create one that handles updates, logs the activity, and prepares for a smooth restart (if needed).- Create a Folder Structure for Organization:
- Go to the root of your
C:
drive and manually create a folder namedScripts
. - Inside
Scripts
, create another folder calledLogs
. This will store your logs for easy troubleshooting. - Create the PowerShell Script:
- Open Notepad and paste this text:
Code:powershell $LogPath = "C:\Scripts\Logs\UpdateLog_$(Get-Date -Format yyyy-MM-dd_hh-mm-ss).txt" Start-Transcript -Path $LogPath Install-WindowsUpdate -AcceptAll -AutoReboot -Verbose | Tee-Object -FilePath $LogPath -Append Stop-Transcript
- Save the file as
RunWindowsUpdate.ps1
in a location of your choice (preferably in theC:\Scripts
folder).
- Checks for updates.
- Installs updates.
- Automatically reboots the PC if required.
- Logs all activity so you can trace what happened.
- Unblock the Script:
PowerShell may block scripts from running for security reasons. To unblock your masterpiece:
Code:Unb-File "C:\Scripts\RunWindowsUpdate.ps1"
Step 3: Automating the Process with Task Scheduler
Now that your script is set up, let’s make it run without any manual intervention.- Open Task Scheduler:
- Search for "Task Scheduler" in the Start menu and open it.
- Create a Basic Task:
- Select Create Basic Task from the right-hand menu.
- Give it a name like “Automatic Windows Updates”.
- Choose Daily for the task trigger and set a convenient time (such as 3:00 AM).
- Set the Action:
- Under Action, choose Start a Program.
- For the program name, enter:
Code:PowerShell.exe
- In the arguments box, enter:
Code:-NoProfile -WindowStyle Hidden -File "C:\Scripts\RunWindowsUpdate.ps1"
- Finalize the Settings:
- Opt to "Run with highest privileges."
- (Optional) Allow the task to run on battery by unchecking the "Start only if on AC power" condition.
- Save your task and you’re good to go.
Bonus Tweaks and Advanced Features
The basic script is simple but leaves room for enhancement. Here are some ideas if you’re ready to take things to the next level:1. Include Microsoft Updates
Expand the script to include Microsoft software updates (e.g., Office). Update theInstall-WindowsUpdate
line:
Code:
Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot -Verbose | Tee-Object -FilePath $LogPath -Append
2. Throttle Internet Bandwidth
Running updates across several PCs? Avoid hogging your bandwidth by throttling it:
Code:
Install-WindowsUpdate -ThrottleDownload 2Mbps -AcceptAll -AutoReboot -Verbose | Tee-Object -FilePath $LogPath -Append
3. Remote Updates for Multiple Machines
Enable PowerShell Remoting (on all target PCs):
Code:
Enable-PSRemoting -Force
Code:
Import-Module PSWindowsUpdate
Making Peace with Windows Updates
And there you have it—Windows Update, tamed and scheduled to work for you. No more surprise reboots or work-interrupting delays. Whether you’re managing a single PC or handling updates across your home network, PowerShell gives you control over how and when updates happen.Pro Tip:
- Periodically check the logs in your
C:\Scripts\Logs
folder to ensure everything runs smoothly. - Avoid scheduling the update during power-sensitive hours for laptops, unless it's absolutely necessary.
Source: XDA Tired of dealing with Windows updates? Here's how to automate them with PowerShell
Last edited by a moderator: