From 5d886f3b3775b2f63dd543a37da497b91c518cb9 Mon Sep 17 00:00:00 2001 From: Paul Mataruso Date: Sun, 6 Jul 2025 17:12:09 +0000 Subject: [PATCH] Add WSUS_Remove_Install.ps1 --- WSUS_Remove_Install.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 WSUS_Remove_Install.ps1 diff --git a/WSUS_Remove_Install.ps1 b/WSUS_Remove_Install.ps1 new file mode 100644 index 0000000..1cf65e2 --- /dev/null +++ b/WSUS_Remove_Install.ps1 @@ -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