-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWSUS-Maintenance.ps1
More file actions
37 lines (32 loc) · 1.12 KB
/
WSUS-Maintenance.ps1
File metadata and controls
37 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# WSUS-Maintenance.ps1
# https://github.com/timkent/wsus-scripts
try {
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
}
catch {
throw "Problem running GetUpdateServer()"
}
try {
$updates = $wsus.GetUpdates()
}
catch {
throw "Problem running GetUpdates()"
}
# Accept EULA for all updates
if ($license = $updates | Where-Object {$_.RequiresLicenseAgreementAcceptance}) {
$license | ForEach-Object {$_.AcceptLicenseAgreement()}
}
Remove-Variable license, updates
# WSUS maintenance tasks
if ($cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope) {
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupScope.DeclineExpiredUpdates = $true
$cleanupScope.CleanupObsoleteUpdates = $true
$cleanupScope.CompressUpdates = $true
$cleanupScope.CleanupObsoleteComputers = $true
$cleanupScope.CleanupUnneededContentFiles = $true
if ($cleanupManager = $wsus.GetCleanupManager()) {
$cleanupManager.PerformCleanup($cleanupScope)
}
}