Auto-commit: 2025-10-31 08:55:43

This commit is contained in:
David Wuibaille
2025-10-31 08:55:43 +01:00
parent 9bb5ad24bb
commit 24c0c6509f
33 changed files with 13144 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#Requires -RunAsAdministrator
[CmdletBinding()]
param(
[string]$ServerName = 'localhost',
[int]$Port = 8530,
[switch]$UseSsl
)
# Load the WSUS admin assembly explicitly if the module isn't present
$wsusDll = "$env:ProgramFiles\Update Services\Tools\Microsoft.UpdateServices.Administration.dll"
if (-not (Get-Module -ListAvailable UpdateServices)) {
if (Test-Path $wsusDll) { Add-Type -Path $wsusDll } else { throw "WSUS Admin DLL not found: $wsusDll" }
}
try {
$wsusServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($ServerName, [bool]$UseSsl, $Port)
$cleanupInterface = $wsusServer.GetCleanupManager()
$cleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupScope.DeclineExpiredUpdates = $true
$cleanupScope.CleanupObsoleteComputers = $true
$cleanupScope.CleanupObsoleteUpdates = $true
$cleanupScope.CompressUpdates = $true
$cleanupScope.CleanupUnneededContentFiles = $true
$cleanupInterface.PerformCleanup($cleanupScope)
Write-Host "WSUS cleanup completed."
}
catch {
Write-Error "WSUS cleanup failed: $($_.Exception.Message)"
exit 1
}

28
cleanup-server/readme.md Normal file
View File

@@ -0,0 +1,28 @@
# WSUS Cleanup (PowerShell)
Powershell scripts to run a safe, repeatable **WSUS** cleanup:
- Decline superseded/expired updates
- Remove obsolete updates/computers
- Compress updates
- Delete unneeded content files
Works with the supported WSUS cmdlets (`UpdateServices` module). A legacy .NET fallback is included.
---
## Requirements
- Run on the WSUS server in an **elevated** PowerShell session.
- WSUS PowerShell module: `UpdateServices` (installed with WSUS/RSAT).
- Port **8530** (HTTP) or **8531** (HTTPS).
- Expect long runtimes on large servers; schedule outside business hours.
## Quick start
```powershell
# Standard full cleanup (HTTP 8530)
.\Wsus-Cleanup.ps1 -Verbose
# HTTPS on 8531
.\Wsus-Cleanup.ps1 -UseSsl -Port 8531 -Verbose
```