Add WSUS_Remove_Install.ps1

This commit is contained in:
2025-07-06 17:12:09 +00:00
parent bdb6e156db
commit 5d886f3b37

21
WSUS_Remove_Install.ps1 Normal file
View File

@@ -0,0 +1,21 @@
# === 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