-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWSUS Cleanup.ps1
148 lines (118 loc) · 4.88 KB
/
WSUS Cleanup.ps1
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
set-executionpolicy RemoteSigned
$WsusServer = ([system.net.dns]::GetHostByName('localhost')).hostname
$UseSSL = $false
$WsusName = "localhost"
$PortNumber = 8530
$WSUS = Get-WsusServer -Name $WsusName -PortNumber $PortNumber
$TrialRun = 0
# 1 = Yes
# 0 = No#
#Ermittle Sprache
[String]$Sprache = [CultureInfo]::InstalledUICulture | select TwoLetter*
$Sprache = $Sprache.Remove(0,27)
$Sprache= $Sprache.Replace("}",$null)
####Sprachtexte anpassen
if($Sprache -eq "de")
{
#echo "Deutsche Text ausgabe " "`0"
$IA64_text =" Itanium updates wurden abgelehnt"
$ARM64_text =" ARM64 Updates wurden abgelehnt"
$embedded_text =" Windows Embedded Updates wurden abgelehnt"
$Office64_text =" MS Office 64-Bit wurden abgelehnt"
$LanguagePack_text =" Language Interface Packs / Sprachpakete wurden abgelehnt"
$Start_Name ="WSUS Reinigung gestartet"
$IA64_titel ="Itanium updates werden abgelehnt"
$ARM64_titel ="ARM64 Updates werden abgelehnt"
$embedded_titel ="Windows Embedded Updates werden abgelehnt"
$Office64_titel ="MS Office 64-Bit werden abgelehnt"
$LanguagePack_titel ="Language Interface Packs / Sprachpakete werden abgelehnt"
$Cleaning_titel = "Reinigung gestartet"
}
else
{
#echo "Englische Text ausgabe " "`0"
$IA64_text =" Itanium updates were declined"
$ARM64_text =" ARM64 Updates were declined"
$embedded_text =" Windows Embedded Updates were declined"
$Office64_text =" MS Office 64-Bit were declined"
$LanguagePack_text =" Language Interface Packs were declined"
$Start_Name ="WSUS cleaning started"
$IA64_titel ="Itanium updates werden abgelehnt"
$ARM64_titel ="ARM64 Updates werden abgelehnt"
$embedded_titel ="Windows Embedded Updates werden abgelehnt"
$Office64_titel ="MS Office 64-Bit werden abgelehnt"
$LanguagePack_titel ="Language Interface Packs / Sprachpakete werden abgelehnt"
$Cleaning_titel = "Reinigung gestartet"
}
echo "################## $Start_Name ##################"
# Connect to the WSUS 3.0 interface.
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$WsusServerAdminProxy = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WsusServer,$UseSSL,$PortNumber);
# Suche Updates nach Namen und lehne diese ab
# Itanium/IA64
echo "$IA64_titel"
$itanium = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match "ia64|itanium"}
$IA64_counted = $itanium.count
If ($itanium.count -lt 1)
{
$IA64_counted = 0
}
If ($TrialRun -eq 0 -and $itanium.count -gt 0)
{
$itanium | %{$_.Decline()}
}
echo "$IA64_counted $IA64_text"
echo "$ARM64_titel"
# ARM64
$arm64 = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match "ARM64"}
$ARM64_counted = $arm64.count
If ($ARM64.count -lt 1)
{
$ARM64_counted = 0
}
If ($TrialRun -eq 0 -and $arm64.count -gt 0)
{
$ARM64 | %{$_.Decline()}
}
echo "$ARM64_counted $ARM64_text"
echo "$embedded_titel"
# Windows Embedded
$embedded = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match "Windows Embedded Standard"}
$embedded_counted = $embedded.count
If ($embedded.count -lt 1)
{
$embedded_counted = 0
}
If ($TrialRun -eq 0 -and $embedded.count -gt 0)
{
$embedded | %{$_.Decline()}
}
echo "$embedded_counted $embedded_text"
echo "$Office64_titel"
# MS Office 64-Bit
$Office64 = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match "Excel|Lync|Office|Outlook|Powerpoint|Visio|word" -and $_.Title -match "64-bit"}
$Office64_count = $Office64.count
If ($Office64.count -lt 1)
{
$Office64_count = 0
}
If ($TrialRun -eq 0 -and $Office64.count -gt 0)
{
$Office64 | %{$_.Decline()}
}
echo "$Office64_count $Office64_text"
echo "$LanguagePack_titel"
# Language Pack
$LanguagePack = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match "Language Interface Pack|LanguageInterfacePack|LanguageFeatureOnDemand|Sprachpaket f|Language Pack - Windows 10 -|LanguagePack - Windows 10 Insider Preview|Lan Pack (Language Features)"}
$LanguagePack_counted = $LanguagePack.count
If ($LanguagePack.count -lt 1)
{
$LanguagePack_counted = 0
}
If ($TrialRun -eq 0 -and $LanguagePack.count -gt 0)
{
$LanguagePack | %{$_.Decline()}
}
echo "$LanguagePack_counted $LanguagePack_text"
echo "$Cleaning_titel"
Invoke-WsusServerCleanup -UpdateServer $WSUS -DeclineExpiredUpdates -DeclineSupersededUpdates -CleanupObsoleteUpdates -CleanupUnneededContentFiles -CompressUpdates