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

Resetting an Active Directory (AD) Administrator password Method-2

April 4, 2025April 4, 2025

Method 1: Reset via Another Domain Admin If you have access to another domain admin account, you can reset the password easily: Method 2: Reset via Command Line (If Another Admin Account Exists) Method 3: Reset via NTDSUTIL (If No Other Admin Account is Available) If you are locked out…

Read More

Trouble shooting on Dc when all FSMO roles transferred to new server and after shutting down the old server it search for the OLD DC

April 11, 2025April 11, 2025

When you’ve transferred all FSMO (Flexible Single Master Operations) roles to a new Domain Controller (DC) and shut down the old DC, yet clients or other DCs are still searching for the old server, it usually means residual references to the old DC are lingering in Active Directory or DNS….

Read More

Open-Source 2FA (Two-Factor Authentication) solutions for Active Directory

April 7, 2025

🔐 1. privacyIDEA 🔐 2. LinOTP 🔐 3. Authelia 🔐 4. Aegis Secure Login (for Windows) 🧰 5. Keycloak (w/ FreeIPA or LDAP) Bonus: RADIUS + AD + 2FA Gateway Stack If you’re into building your own stack: This setup works great for adding 2FA to VPNs, SSH, and web…

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 }