Skip to content
Tech Master Tech Master

OneStopTechnical Forum

  • Books
  • AI
  • Networking
  • Windows
  • Linux
  • Cloud
  • Mac
  • Active Directory
  • Azure
  • Cloud
  • Exchange
  • M365
  • Server 2025
  • Storage
  • Vsphere
  • Website
  • Database
  • Security
  • Knowledge Base
  • VPN
Tech Master
Tech Master

OneStopTechnical Forum

Windows update done through script

blog.payperitem.com, April 3, 2025April 3, 2025

You can update Windows locally using a PowerShell script. Here’s a script that automates the update process, including checking for updates, installing them, and restarting the system if necessary.

PowerShell Script for Local Windows Update

powershell# Run as administrator
$ErrorActionPreference = "Stop"

# Check if running as Administrator
function Test-Admin {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

if (-Not (Test-Admin)) {
Write-Host "This script must be run as Administrator!" -ForegroundColor Red
exit 1
}

# Install Windows Update module if not installed
if (-not (Get-Module -Name PSWindowsUpdate -ListAvailable)) {
Write-Host "Installing Windows Update module..."
Install-Module PSWindowsUpdate -Force -AllowClobber -Scope CurrentUser
}

# Import Windows Update module
Import-Module PSWindowsUpdate

# Check for updates
Write-Host "Checking for Windows Updates..."
$Updates = Get-WindowsUpdate -MicrosoftUpdate -AcceptAll

# Install updates
if ($Updates.Count -gt 0) {
Write-Host "Installing updates..."
Get-WindowsUpdate -Install -AcceptAll -IgnoreReboot
} else {
Write-Host "No updates available."
}

# Prompt for restart if required
if (Get-WURebootStatus) {
Write-Host "A restart is required. Restarting in 10 seconds..."
Start-Sleep -Seconds 10
Restart-Computer -Force
} else {
Write-Host "No restart required."
}

Write-Host "Windows update process completed!" -ForegroundColor Green

How to Use:

  1. Run PowerShell as Administrator
  2. Save the script as update_windows.ps1
  3. Execute the script:
  4. powershell
  5. Set-ExecutionPolicy Bypass -Scope Process -Force .\update_windows.ps1

This script:

  • Ensures it’s running as an administrator
  • Installs the PSWindowsUpdate module if not available
  • Checks for Windows updates
  • Installs updates without requiring user input
  • Restarts the system if necessary

Active Directory Windows

Post navigation

Previous post
Next post

Related Posts

Windows

How to close an unresponsive app in Windows

January 21, 2025January 26, 2025

We’ve all been there. You’re working on an important document or playing your favorite game, and suddenly, the application freezes. The window becomes unresponsive; no matter how much you click or tap, it just sits there. While it’s frustrating, there are several methods you can use to close unresponsive applications…

Read More

Reset Active Directory Administrator password

April 4, 2025April 4, 2025

Method 1: Using Active Directory Users and Computers (ADUC) If you have access to another account with sufficient permissions (like another Domain Administrator), you can reset the password through the Active Directory Users and Computers snap-in. Method 2: Using PowerShell If you have sufficient permissions, you can also use PowerShell…

Read More

Microsoft brings new group policy for optional updates in Windows 11

March 8, 2025April 2, 2025

Now that Windows 11 only receives one feature update per year, Microsoft is delivering many new features via optional non-security updates or CUs in the second week of each month. A new group policy causes the automatic installation of optional updates, either with or without new features. By default, new…

Read More

Recent Posts

  • List of AD Schema Versions
  • OldNewExplorer Free Download For Windows 11, 10, 8 and 7 [Latest Version]
  • How to Get the Classic (old) Context Menu on Windows 11
  • BitLocker Recovery Keys
  • Active Directory and Server hardening

Recent Comments

No comments to show.
June 2025
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« May    
Log in
©2025 Tech Master | WordPress Theme by SuperbThemes
  • Login
  • Sign Up
Forgot Password?
Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.
body::-webkit-scrollbar { width: 7px; } body::-webkit-scrollbar-track { border-radius: 10px; background: #f0f0f0; } body::-webkit-scrollbar-thumb { border-radius: 50px; background: #dfdbdb }