Files
WSUS_Installer/WSUS_Remove_Install.ps1

22 lines
1.4 KiB
PowerShell

# === REMOVE ALL EXISTING WSUS FEATURES ===
Write-Host "==> Removing any existing WSUS components..." -ForegroundColor Cyan
Uninstall-WindowsFeature UpdateServices, UpdateServices-Services, UpdateServices-UI, UpdateServices-WidDB, UpdateServices-DB -Remove
# === DELETE OLD WSUS FILES AND DATABASE ===
Write-Host "==> Deleting old WSUS folders and WID database (if exists)..." -ForegroundColor Cyan
Remove-Item -Path "C:\WSUS" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Program Files\Update Services" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\WID\Data\SUSDB.mdf" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\Windows\WID\Data\SUSDB_log.ldf" -Force -ErrorAction SilentlyContinue
# === INSTALL WSUS WITH WID, USING ISO MOUNTED AT E:, For if the server has no internet or windows update is not working ===
Write-Host "==> Installing WSUS with WID from mounted ISO..." -ForegroundColor Cyan
Install-WindowsFeature UpdateServices, UpdateServices-Services, UpdateServices-WidDB, UpdateServices-UI `
-Source E:\sources\sxs -IncludeManagementTools
# === RUN POSTINSTALL TASK TO CONFIGURE WSUS ===
Write-Host "==> Running WSUS post-install task..." -ForegroundColor Cyan
& "C:\Program Files\Update Services\Tools\wsusutil.exe" postinstall CONTENT_DIR="C:\WSUS"
Write-Host "`n✅ WSUS installation complete. Open the console from Server Manager > Tools > Windows Server Update Services." -ForegroundColor Green