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

PowerShell automation script to install Wsus Server

blog.payperitem.com, April 11, 2025

Configure, and manage a WSUS server, including:

  • Installing the WSUS role
  • Setting content storage
  • Running post-install tasks
  • Configuring sync settings
  • Setting update categories/classifications
  • Enabling automatic synchronization
  • Running cleanup tasks

🚀 WSUS PowerShell Automation Script

powershell# ================================
# WSUS Automated Setup Script
# ================================

# VARIABLES
$wsusContentPath = "D:\WSUS"
$wsusSQLInstance = "WID" # or use "SERVERNAME\INSTANCE" for full SQL
$wsusPort = 8530
$productsToSync = @(
"Windows 10",
"Windows Server 2019"
)
$classificationsToSync = @(
"Security Updates",
"Critical Updates"
)

# -------------------------------
# 1. Install WSUS Role & Features
# -------------------------------
Install-WindowsFeature -Name UpdateServices, UpdateServices-WidDB, UpdateServices-Services -IncludeManagementTools

# -------------------------------
# 2. Run Post-Install Configuration
# -------------------------------
& "C:\Program Files\Update Services\Tools\wsusutil.exe" postinstall CONTENT_DIR=$wsusContentPath

# -------------------------------
# 3. Import WSUS Module
# -------------------------------
Import-Module -Name UpdateServices

# -------------------------------
# 4. Connect to WSUS Server
# -------------------------------
$wsus = Get-WsusServer -Name $env:COMPUTERNAME -PortNumber $wsusPort

# -------------------------------
# 5. Configure Products to Sync
# -------------------------------
$wsus.GetSubscription().GetUpdateCategories() | ForEach-Object {
if ($productsToSync -contains $_.Title) {
$_.Children | ForEach-Object { $_.Enabled = $true }
$_.Enabled = $true
}
}

# -------------------------------
# 6. Configure Classifications to Sync
# -------------------------------
$wsus.GetSubscription().GetUpdateClassifications() | ForEach-Object {
if ($classificationsToSync -contains $_.Title) {
$_.Enabled = $true
}
}

# -------------------------------
# 7. Configure Sync Schedule
# -------------------------------
$subscription = $wsus.GetSubscription()
$subscription.SynchronizeAutomatically = $true
$subscription.SynchronizeAutomaticallyTimeOfDay = [datetime]::Now.TimeOfDay
$subscription.Save()

# -------------------------------
# 8. Start Initial Sync
# -------------------------------
$wsus.GetSubscription().StartSynchronization()

# -------------------------------
# 9. Run WSUS Cleanup Tasks
# -------------------------------
$cleanupManager = $wsus.GetCleanupManager()
$cleanupManager.PerformCleanup(
$true, # ObsoleteUpdates
$true, # UnneededContentFiles
$true, # ExpiredUpdates
$true, # SupersededUpdates
$true # Computers not contacting server
)

Write-Host "WSUS Setup & Initial Configuration Complete!" -ForegroundColor Green
ScriptDownload
Active Directory Security Server 2025 Windows

Post navigation

Previous post
Next post

Related Posts

Network Security & Automated Monitoring Hardening Guide

April 3, 2025April 3, 2025

🛡️ Network Security Hardening 1️⃣ Perimeter Defense (Firewall & DDoS Mitigation) ✅ Layered Firewalls: ✅ DDoS Protection: ✅ Strict Default Firewall Policies: 2️⃣ Network-Level Hardening (TCP/IP Security) ✅ Disable Unused Network Services ✅ Enable TCP/IP Hardening (Sysctl Settings) ✅ ARP & MAC Spoofing Protection ✅ Implement TLS Everywhere ✅ WireGuard…

Read More

Active Directory Real-Scenario Q&A

April 29, 2025

Basics and Core Concepts (1–10) Q1. What is Active Directory?A1. Active Directory is Microsoft’s directory service that stores information about objects on the network and makes this information easy for administrators and users to find and use. Q2. What is a domain in Active Directory?A2. A domain is a logical…

Read More

Types of Backups

April 3, 2025April 3, 2025

1. Full Backup A complete copy of all selected data is taken.✅ Pros: Simplifies recovery, standalone backup.❌ Cons: Time-consuming, high storage usage. 2. Incremental Backup Only data that has changed since the last backup (of any type) is copied.✅ Pros: Saves time and storage.❌ Cons: Recovery can be slow, as…

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 }