forked from bcdady/MyScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ClientWSUSSetting.ps1
229 lines (213 loc) · 10.8 KB
/
Get-ClientWSUSSetting.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
function Get-ClientWSUSSetting {
<#
.SYNOPSIS
Retrieves the wsus client settings on a local or remote system.
.DESCRIPTION
Retrieves the wsus client settings on a local or remote system.
.PARAMETER Computername
Name of computer to connect to. Can be a collection of computers.
.PARAMETER ShowEnvironment
Display only the Environment settings.
.PARAMETER ShowConfiguration
Display only the Configuration settings.
.NOTES
Name: Get-WSUSClient
Author: Boe Prox
DateCreated: 02DEC2011
.LINK
https://learn-powershell.net
.EXAMPLE
Get-ClientWSUSSetting -Computername TestServer
RescheduleWaitTime : NA
AutoInstallMinorUpdates : NA
TargetGroupEnabled : NA
ScheduledInstallDay : NA
DetectionFrequencyEnabled : 1
WUServer : http://wsus.com
Computername : TestServer
RebootWarningTimeoutEnabled : NA
ElevateNonAdmins : NA
ScheduledInstallTime : NA
RebootRelaunchTimeout : 10
ScheduleInstallDay : NA
RescheduleWaitTimeEnabled : NA
DisableWindowsUpdateAccess : NA
AUOptions : 3
DetectionFrequency : 4
RebootWarningTimeout : NA
ScheduleInstallTime : NA
WUStatusServer : http://wsus.com
TargetGroup : NA
RebootRelaunchTimeoutEnabled : 1
UseWUServer : 1
NoAutoRebootWithLoggedOnUsers : 1
Description
-----------
Displays both Environment and Configuration settings for TestServer
.EXAMPLE
Get-ClientWSUSSetting -Computername Server1 -ShowEnvironment
Computername : Server1
TargetGroupEnabled : NA
TargetGroup : NA
WUStatusServer : http://wsus.com
WUServer : http://wsus.com
DisableWindowsUpdateAccess : 1
ElevateNonAdmins : 0
Description
-----------
Displays the Environment settings for Server1
.Example
Get-ClientWSUSSetting -Computername Server1 -ShowConfiguration
ScheduledInstallTime : NA
AutoInstallMinorUpdates : 0
ScheduledInstallDay : NA
Computername : Server1
RebootWarningTimeoutEnabled : NA
RebootWarningTimeout : NA
NoAUAsDefaultShutdownOption : NA
RebootRelaunchTimeout : NA
DetectionFrequency : 4
ScheduleInstallDay : NA
RescheduleWaitTime : NA
RescheduleWaitTimeEnabled : 0
AUOptions : 3
NoAutoRebootWithLoggedOnUsers : 1
DetectionFrequencyEnabled : 1
ScheduleInstallTime : NA
NoAUShutdownOption : NA
RebootRelaunchTimeoutEnabled : NA
UseWUServer : 1
IncludeRecommendedUpdates : NA
Description
-----------
Displays the Configuration settings for Server1
#>
[cmdletbinding()]
Param (
[parameter(ValueFromPipeLine = $True)]
[string[]]$Computername = $Env:Computername,
[parameter()]
[switch]$ShowEnvironment,
[parameter()]
[switch]$ShowConfiguration
)
Begin {
$EnvKeys = 'WUServer','WUStatusServer','ElevateNonAdmins','TargetGroupEnabled','TargetGroup','DisableWindowsUpdateAccess'
$ConfigKeys = 'AUOptions','AutoInstallMinorUpdates','DetectionFrequency','DetectionFrequencyEnabled','NoAutoRebootWithLoggedOnUsers',
'NoAutoUpdate','RebootRelaunchTimeout','RebootRelaunchTimeoutEnabled','RebootWarningTimeout','RebootWarningTimeoutEnabled','RescheduleWaitTime','RescheduleWaitTimeEnabled',
'ScheduleInstallDay','ScheduleInstallTime','UseWUServer'
}
Process {
$PSBoundParameters.GetEnumerator() | ForEach-Object {
Write-Verbose ('{0}' -f $_)
}
ForEach ($Computer in $Computername) {
If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
$WSUSEnvhash = @{}
$WSUSConfigHash = @{}
$ServerReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$Computer)
#Get WSUS Client Environment Options
$WSUSEnv = $ServerReg.OpenSubKey('Software\Policies\Microsoft\Windows\WindowsUpdate')
$subkeys = @($WSUSEnv.GetValueNames())
$NoData = @(Compare-Object -ReferenceObject $EnvKeys -DifferenceObject $subkeys | Select-Object -ExpandProperty InputObject)
ForEach ($item in $NoData) {
$WSUSEnvhash[$item] = 'NA'
}
$Data = @(Compare-Object -ReferenceObject $EnvKeys -DifferenceObject $subkeys -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject)
ForEach ($key in $Data) {
If ($key -eq 'WUServer') {
$WSUSEnvhash['WUServer'] = $WSUSEnv.GetValue('WUServer')
}
If ($key -eq 'WUStatusServer') {
$WSUSEnvhash['WUStatusServer'] = $WSUSEnv.GetValue('WUStatusServer')
}
If ($key -eq 'ElevateNonAdmins') {
$WSUSEnvhash['ElevateNonAdmins'] = $WSUSEnv.GetValue('ElevateNonAdmins')
}
If ($key -eq 'TargetGroupEnabled') {
$WSUSEnvhash['TargetGroupEnabled'] = $WSUSEnv.GetValue('TargetGroupEnabled')
}
If ($key -eq 'TargetGroup') {
$WSUSEnvhash['TargetGroup'] = $WSUSEnv.GetValue('TargetGroup')
}
If ($key -eq 'DisableWindowsUpdateAccess') {
$WSUSEnvhash['DisableWindowsUpdateAccess'] = $WSUSEnv.GetValue('DisableWindowsUpdateAccess')
}
}
#Get WSUS Client Configuration Options
$WSUSConfig = $ServerReg.OpenSubKey('Software\Policies\Microsoft\Windows\WindowsUpdate\AU')
$subkeys = @($WSUSConfig.GetValueNames())
$NoData = @(Compare-Object -ReferenceObject $ConfigKeys -DifferenceObject $subkeys | Select-Object -ExpandProperty InputObject)
ForEach ($item in $NoData) {
$WSUSConfighash[$item] = 'NA'
}
$Data = @(Compare-Object -ReferenceObject $ConfigKeys -DifferenceObject $subkeys -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject)
ForEach ($key in $Data) {
If ($key -eq 'AUOptions') {
$WSUSConfighash['AUOptions'] = $WSUSConfig.GetValue('AUOptions')
}
If ($key -eq 'AutoInstallMinorUpdates') {
$WSUSConfighash['AutoInstallMinorUpdates'] = $WSUSConfig.GetValue('AutoInstallMinorUpdates')
}
If ($key -eq 'DetectionFrequency') {
$WSUSConfighash['DetectionFrequency'] = $WSUSConfig.GetValue('DetectionFrequency')
}
If ($key -eq 'DetectionFrequencyEnabled') {
$WSUSConfighash['DetectionFrequencyEnabled'] = $WSUSConfig.GetValue('DetectionFrequencyEnabled')
}
If ($key -eq 'NoAutoRebootWithLoggedOnUsers') {
$WSUSConfighash['NoAutoRebootWithLoggedOnUsers'] = $WSUSConfig.GetValue('NoAutoRebootWithLoggedOnUsers')
}
If ($key -eq 'RebootRelaunchTimeout') {
$WSUSConfighash['RebootRelaunchTimeout'] = $WSUSConfig.GetValue('RebootRelaunchTimeout')
}
If ($key -eq 'RebootRelaunchTimeoutEnabled') {
$WSUSConfighash['RebootRelaunchTimeoutEnabled'] = $WSUSConfig.GetValue('RebootRelaunchTimeoutEnabled')
}
If ($key -eq 'RebootWarningTimeout') {
$WSUSConfighash['RebootWarningTimeout'] = $WSUSConfig.GetValue('RebootWarningTimeout')
}
If ($key -eq 'RebootWarningTimeoutEnabled') {
$WSUSConfighash['RebootWarningTimeoutEnabled'] = $WSUSConfig.GetValue('RebootWarningTimeoutEnabled')
}
If ($key -eq 'RescheduleWaitTime') {
$WSUSConfighash['RescheduleWaitTime'] = $WSUSConfig.GetValue('RescheduleWaitTime')
}
If ($key -eq 'RescheduleWaitTimeEnabled') {
$WSUSConfighash['RescheduleWaitTimeEnabled'] = $WSUSConfig.GetValue('RescheduleWaitTimeEnabled')
}
If ($key -eq 'ScheduleInstallDay') {
$WSUSConfighash['ScheduleInstallDay'] = $WSUSConfig.GetValue('ScheduleInstallDay')
}
If ($key -eq 'ScheduleInstallTime') {
$WSUSConfighash['ScheduleInstallTime'] = $WSUSConfig.GetValue('ScheduleInstallTime')
}
If ($key -eq 'UseWUServer') {
$WSUSConfighash['UseWUServer'] = $WSUSConfig.GetValue('UseWUServer')
}
}
#Display Output
If ((-Not ($PSBoundParameters['ShowEnvironment'] -OR $PSBoundParameters['ShowConfiguration'])) -OR `
($PSBoundParameters['ShowEnvironment'] -AND $PSBoundParameters['ShowConfiguration'])) {
Write-Verbose 'Displaying everything'
$WSUSHash = ($WSUSEnvHash + $WSUSConfigHash)
$WSUSHash['Computername'] = $Computer
New-Object PSObject -Property $WSUSHash
} Else {
If ($PSBoundParameters['ShowEnvironment']) {
Write-Verbose 'Displaying environment settings'
$WSUSEnvHash['Computername'] = $Computer
New-Object PSObject -Property $WSUSEnvhash
}
If ($PSBoundParameters['ShowConfiguration']) {
Write-Verbose 'Displaying Configuration settings'
$WSUSConfigHash['Computername'] = $Computer
New-Object PSObject -Property $WSUSConfigHash
}
}
} Else {
Write-Warning ('{0}: Unable to connect!' -f $Computer)
}
}
}
}