forked from edemilliere/Misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-WindowsUpdateConfiguration.ps1
274 lines (259 loc) · 15.7 KB
/
Get-WindowsUpdateConfiguration.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
Function Get-WindowsUpdateConfiguration{
<#
.SYNOPSIS
Get the configuration of the WSUS agent based on registry keys.
.DESCRIPTION
This function use OpenRemoteBaseKey from .Net to query remote computer.
.PARAMETER ComputerName
Named of the remote computer.
Defaulted to the local host.
.EXAMPLE
Get-WindowsUpdateConfiguration -ComputerName Server1
Get the WSUS agent configuration from registry.
.EXAMPLE
Get-ADForest | Select-Object -ExpandProperty Domains | % {Get-ADComputer -Filter {OperatingSystem -like '*server*'} -Server $_} | Select-Object -ExpandProperty Name | Get-windowsUpdateConfiguration | Export-Csv -NoTypeInformation -Delimiter ';' 'windowsUpdateConfiguration.csv'
Get all the computers inside the curent forest and get the WSUS agent configuration for all of them. Can be quite long.
.NOTES
.LINK
https://itfordummies.net
.INPUTS
.OUTPUTS
#>
Param(
[Parameter(ValueFromPipeline = $true)]
[String[]]$ComputerName = $env:COMPUTERNAME
)
Begin{
$Hive = [Microsoft.Win32.RegistryHive]::LocalMachine
}
Process{
try{
if(Test-Connection -ComputerName $ComputerName -Quiet -Count 3 -ErrorAction Stop){
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive, $ComputerName)
$WindowsUpdateKeyPath = 'Software\Policies\Microsoft\Windows\WindowsUpdate'
$AutomaticUpdateKeyPath = 'Software\Policies\Microsoft\Windows\WindowsUpdate\AU'
try{
$WindowsUpdateKey = $reg.OpenSubKey($WindowsUpdateKeyPath)
try{
$AcceptTrustedPublisherCerts = $WindowsUpdateKey.GetValue('AcceptTrustedPublisherCerts')
}
catch{
$AcceptTrustedPublisherCerts = $_
}
try{
$DisableWindowsUpdateAccess = $WindowsUpdateKey.GetValue('DisableWindowsUpdateAccess')
}
catch{
$DisableWindowsUpdateAccess = $_
}
try{
$ElevateNonAdmins = $WindowsUpdateKey.GetValue('ElevateNonAdmins')
}
catch{
$ElevateNonAdmins = $_
}
try{
$TargetGroup = $WindowsUpdateKey.GetValue('TargetGroup')
}
catch{
$TargetGroup = $_
}
try{
$TargetGroupEnabled = $WindowsUpdateKey.GetValue('TargetGroupEnabled')
}
catch{
$TargetGroupEnabled = $_
}
try{
$WUServer = $WindowsUpdateKey.GetValue('WUServer')
}
catch{
$WUServer = $_
}
try{
$WUStatusServer = $WindowsUpdateKey.GetValue('WUStatusServer')
}
catch{
$WUStatusServer = $_
}
}
catch{
$AcceptTrustedPublisherCerts = "$WindowsUpdateKeyPath : $_"
$DisableWindowsUpdateAccess = "$WindowsUpdateKeyPath : $_"
$ElevateNonAdmins = "$WindowsUpdateKeyPath : $_"
$TargetGroup = "$WindowsUpdateKeyPath : $_"
$TargetGroupEnabled = "$WindowsUpdateKeyPath : $_"
$WUServer = "$WindowsUpdateKeyPath : $_"
$WUStatusServer = "$WindowsUpdateKeyPath : $_"
}
try{
$AutomaticUpdateKey = $reg.OpenSubKey($AutomaticUpdateKeyPath)
try{
$AUOptions = switch ($AutomaticUpdateKey.GetValue('AUOptions')){
'2' {'Notify before download.'}
'3' {'Automatically download and notify of installation.'}
'4' {'Automatically download and schedule installation. Only valid if values exist for ScheduledInstallDay and ScheduledInstallTime.'}
'5' {'Automatic Updates is required and users can configure it.'}
Default {$AutomaticUpdateKey.GetValue('AUOptions')}
}
}
catch{$AUOptions = $_}
try{
$AutoInstallMinorUpdates = switch ($AutomaticUpdateKey.GetValue('AutoInstallMinorUpdates')){
'0' {'Treat minor updates like other updates.'}
'1' {'Silently install minor updates.'}
Default {$AutomaticUpdateKey.GetValue('AutoInstallMinorUpdates')}
}
}
catch{$AutoInstallMinorUpdates = $_}
try{
$DetectionFrequency = $AutomaticUpdateKey.GetValue('DetectionFrequency')
}
catch{$DetectionFrequency = $_}
try{
$DetectionFrequencyEnabled = switch ($AutomaticUpdateKey.GetValue('DetectionFrequencyEnabled')){
'0' {'Disable custom detection frequency (use default value of 22 hours).'}
'1' {'Enable detection frequency.'}
Default {$AutomaticUpdateKey.GetValue('DetectionFrequencyEnabled')}
}
}
catch{$DetectionFrequencyEnabled = $_}
try{
$NoAutoRebootWithLoggedOnUsers = switch ($AutomaticUpdateKey.GetValue('NoAutoRebootWithLoggedOnUsers')){
'0' {'Automatic Updates notifies the user that the computer will restart in 15 minutes.'}
'1' {'Logged-on user can decide whether to restart the client computer.'}
Default {$AutomaticUpdateKey.GetValue('NoAutoRebootWithLoggedOnUsers')}
}
}
catch{$NoAutoRebootWithLoggedOnUsers = $_}
try{
$NoAutoUpdate = switch ($AutomaticUpdateKey.GetValue('NoAutoUpdate')){
'0' {'Enable Automatic Updates.'}
'1' {'Disable Automatic Updates.'}
Default {$AutomaticUpdateKey.GetValue('NoAutoUpdate')}
}
}
catch{$NoAutoUpdate = $_}
try{
$RebootRelaunchTimeout = $AutomaticUpdateKey.GetValue('RebootRelaunchTimeout')
}
catch{$RebootRelaunchTimeout = $_}
try{
$RebootRelaunchTimeoutEnabled = switch ($AutomaticUpdateKey.GetValue('RebootRelaunchTimeoutEnabled')){
'0' {'Disable custom RebootRelaunchTimeout(use default value of 10 minutes).'}
'1' {'Enable RebootRelaunchTimeout.'}
Default {$AutomaticUpdateKey.GetValue('RebootRelaunchTimeoutEnabled')}
}
}
catch{$RebootRelaunchTimeoutEnabled = $_}
try{
$RebootWarningTimeout = $AutomaticUpdateKey.GetValue('RebootWarningTimeout')
}
catch{$RebootWarningTimeout = $_}
try{
$RebootWarningTimeoutEnabled = switch ($AutomaticUpdateKey.GetValue('RebootWarningTimeoutEnabled')){
'0' {'Disable custom RebootWarningTimeout (use default value of 5 minutes).'}
'1' {'Enable RebootWarningTimeout.'}
Default {$AutomaticUpdateKey.GetValue('RebootWarningTimeoutEnabled')}
}
}
catch{$RebootWarningTimeoutEnabled = $_}
try{
$RescheduleWaitTime = $AutomaticUpdateKey.GetValue('RescheduleWaitTime')
}
catch{$RescheduleWaitTime = $_}
try{
$RescheduleWaitTimeEnabled = switch ($AutomaticUpdateKey.GetValue('RescheduleWaitTimeEnabled')){
'0' {'Disable RescheduleWaitTime (attempt the missed installation during the next scheduled installation time).'}
'1' {'Enable RescheduleWaitTime .'}
Default {$AutomaticUpdateKey.GetValue('RescheduleWaitTimeEnabled')}
}
}
catch{$RescheduleWaitTimeEnabled = $_}
try{
$ScheduledInstallDay = switch ($AutomaticUpdateKey.GetValue('ScheduledInstallDay')){
'0' {'Every day.'}
'1' {'Sunday (Only valid if AUOptions = 4.)'}
'2' {'Monday (Only valid if AUOptions = 4.)'}
'3' {'Tuesday (Only valid if AUOptions = 4.)'}
'4' {'Wenesday (Only valid if AUOptions = 4.)'}
'5' {'Thursday (Only valid if AUOptions = 4.)'}
'6' {'Friday (Only valid if AUOptions = 4.)'}
'7' {'Saturday (Only valid if AUOptions = 4.)'}
Default {$AutomaticUpdateKey.GetValue('ScheduledInstallDay')}
}
}
catch{$ScheduledInstallDay = $_}
try{
$ScheduledInstallTime = $AutomaticUpdateKey.GetValue('ScheduledInstallTime')
}
catch{$ScheduledInstallTime = $_}
try{
$UseWUServer = switch ($AutomaticUpdateKey.GetValue('UseWUServer')){
'0' {'The computer gets its updates from Microsoft Update. The WUServer value is not respected unless this key is set.'}
'1' {'The computer gets its updates from a WSUS server. The WUServer value is not respected unless this key is set.'}
Default {$AutomaticUpdateKey.GetValue('UseWUServer')}
}
}
catch{$UseWUServer = $_}
}
catch{
$AUOptions = "$AutomaticUpdateKeyPath : $_"
$AutoInstallMinorUpdates = "$AutomaticUpdateKeyPath : $_"
$AUAutoInstallMinorUpdatesOptions = "$AutomaticUpdateKeyPath : $_"
$DetectionFrequency = "$AutomaticUpdateKeyPath : $_"
$DetectionFrequencyEnabled = "$AutomaticUpdateKeyPath : $_"
$NoAutoRebootWithLoggedOnUsers = "$AutomaticUpdateKeyPath : $_"
$NoAutoUpdate = "$AutomaticUpdateKeyPath : $_"
$RebootRelaunchTimeout = "$AutomaticUpdateKeyPath : $_"
$RebootRelaunchTimeoutEnabled = "$AutomaticUpdateKeyPath : $_"
$RebootWarningTimeout = "$AutomaticUpdateKeyPath : $_"
$RebootWarningTimeoutEnabled = "$AutomaticUpdateKeyPath : $_"
$RescheduleWaitTime = "$AutomaticUpdateKeyPath : $_"
$RescheduleWaitTimeEnabled = "$AutomaticUpdateKeyPath : $_"
$ScheduledInstallDay = "$AutomaticUpdateKeyPath : $_"
$ScheduledInstallTime = "$AutomaticUpdateKeyPath : $_"
$UseWUServer = "$AutomaticUpdateKeyPath : $_"
}
}
else{
$AcceptTrustedPublisherCerts = $DisableWindowsUpdateAccess = $ElevateNonAdmins = $TargetGroup = $TargetGroupEnabled = $WUServer = $WUStatusServer = $AUOptions = $AutoInstallMinorUpdates = $AUAutoInstallMinorUpdatesOptions = $DetectionFrequency = $DetectionFrequencyEnabled = $NoAutoRebootWithLoggedOnUsers = $NoAutoUpdate = $RebootRelaunchTimeout = $RebootRelaunchTimeoutEnabled = $RebootWarningTimeout = $RebootWarningTimeoutEnabled = $RescheduleWaitTime = $RescheduleWaitTimeEnabled = $ScheduledInstallDay = $ScheduledInstallTime = $UseWUServer = 'Offline'
}
}#end try inside process
catch{
Write-Warning -Message "$ComputerName : $_"
$AcceptTrustedPublisherCerts = $DisableWindowsUpdateAccess = $ElevateNonAdmins = $TargetGroup = $TargetGroupEnabled = $WUServer = $WUStatusServer = $AUOptions = $AutoInstallMinorUpdates = $AUAutoInstallMinorUpdatesOptions = $DetectionFrequency = $DetectionFrequencyEnabled = $NoAutoRebootWithLoggedOnUsers = $NoAutoUpdate = $RebootRelaunchTimeout = $RebootRelaunchTimeoutEnabled = $RebootWarningTimeout = $RebootWarningTimeoutEnabled = $RescheduleWaitTime = $RescheduleWaitTimeEnabled = $ScheduledInstallDay = $ScheduledInstallTime = $UseWUServer = $_
}
finally{
New-Object -TypeName PSObject -Property @{
ComputerName = "$ComputerName"
AcceptTrustedPublisherCerts = $AcceptTrustedPublisherCerts
DisableWindowsUpdateAccess = $DisableWindowsUpdateAccess
ElevateNonAdmins = $ElevateNonAdmins
TargetGroup = $TargetGroup
TargetGroupEnabled = $TargetGroupEnabled
WUServer = $WUServer
WUStatusServer = $WUStatusServer
AUOptions = $AUOptions
AutoInstallMinorUpdates = $AutoInstallMinorUpdates
AUAutoInstallMinorUpdatesOptions = $AUAutoInstallMinorUpdatesOptions
DetectionFrequency = $DetectionFrequency
DetectionFrequencyEnabled = $DetectionFrequencyEnabled
NoAutoRebootWithLoggedOnUsers = $NoAutoRebootWithLoggedOnUsers
NoAutoUpdate = $NoAutoUpdate
RebootRelaunchTimeout = $RebootRelaunchTimeout
RebootRelaunchTimeoutEnabled = $RebootRelaunchTimeoutEnabled
RebootWarningTimeout = $RebootWarningTimeout
RebootWarningTimeoutEnabled = $RebootWarningTimeoutEnabled
RescheduleWaitTime = $RescheduleWaitTime
RescheduleWaitTimeEnabled = $RescheduleWaitTimeEnabled
ScheduledInstallDay = $ScheduledInstallDay
ScheduledInstallTime = $ScheduledInstallTime
UseWUServer = $UseWUServer
}
#Reset Variables
$AcceptTrustedPublisherCerts = $DisableWindowsUpdateAccess = $ElevateNonAdmins = $TargetGroup = $TargetGroupEnabled = $WUServer = $WUStatusServer = $AUOptions = $AutoInstallMinorUpdates = $AUAutoInstallMinorUpdatesOptions = $DetectionFrequency = $DetectionFrequencyEnabled = $NoAutoRebootWithLoggedOnUsers = $NoAutoUpdate = $RebootRelaunchTimeout = $RebootRelaunchTimeoutEnabled = $RebootWarningTimeout = $RebootWarningTimeoutEnabled = $RescheduleWaitTime = $RescheduleWaitTimeEnabled = $ScheduledInstallDay = $ScheduledInstallTime = $UseWUServer = $null
}
}#EndProcess
End{}
}