forked from proxb/PoshWSUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-PSWSUSUpdate.ps1
240 lines (210 loc) · 8.91 KB
/
Get-PSWSUSUpdate.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
function Get-PSWSUSUpdate {
<#
.SYNOPSIS
Retrieves information from a wsus update.
.DESCRIPTION
Retrieves information from a wsus update. Depending on how the information is presented in the search, more
than one update may be returned.
.PARAMETER Update
String to search for. This can be any string for the update to include
KB article numbers, name of update, category, etc... Use of wildcards (*,%) are not allowed in search!
.PARAMETER IncludeText
Text to include in search
.PARAMETER ExcludeText
Text to exclude from search
.PARAMETER ApprovedState
Approval states to search for
.PARAMETER UpdateType
Update types to search for
.PARAMETER ComputerTargetGroups
List of target groups to search for approvals
.PARAMETER ExcludeOptionalUpdates
Exclude optional updates from the list
.PARAMETER IsWsusInfrastructureUpdate
Filter for WSUS infrastructure updates
.PARAMETER IncludedInstallationState
Installation states to search for
.PARAMETER ExcludedInstallationState
Installation states to exclude
.PARAMETER FromArrivalDate
Minimum arrival date to search for
.PARAMETER ToArrivalDate
Maximum arrival date to search for
.PARAMETER FromCreationDate
Minimum creation date to search for
.PARAMETER ToCreationDate
Maximum creation date to search for
.PARAMETER UpdateApprovalAction
Update approval actions to search for
.PARAMETER UpdateSource
Update sources to search for
.PARAMETER Category
List of update categories to search.
.PARAMETER Classification
List of update classifications to search
.NOTES
Name: Get-PSWSUSUpdate
Author: Boe Prox
Version History:
1.2 | 18 Feb 2015
-Renamed to Get-PSWSUSUpdate
-Add multiple parameters
1.0 | 24 Sept 2010
-Initial Version
.LINK
https://learn-powershell.net
.EXAMPLE
Get-PSWSUSUpdate
Description
-----------
This command will list every update on the WSUS Server.
.EXAMPLE
Get-PSWSUSUpdate -update "Exchange"
Description
-----------
This command will list every update that has 'Exchange' in it.
.EXAMPLE
Get-PSWSUSUpdate -update "KB925474"
Description
-----------
This command will list every update that has 'KB925474' in it.
.EXAMPLE
$Categories = Get-PSWSUSCategory|Where{$_.title -match 'server 2012'}
Get-PSWSUSUpdate -Category $Categories
Description
-----------
Gets all updates matching the Windows Server 2012 category
#>
[cmdletbinding(
DefaultParameterSetName = 'All'
)]
Param(
[Parameter(Position=0,ValueFromPipeline = $True,ParameterSetName = 'Update')]
[string[]]$Update,
[Parameter(ParameterSetName='UpdateScope')]
[string]$IncludeText,
[Parameter(ParameterSetName='UpdateScope')]
[string]$ExcludeText,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.ApprovedStates]$ApprovedState,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.UpdateTypes]$UpdateType,
[Parameter(ParameterSetName='UpdateScope')]
[string[]]$ComputerTargetGroups,
[Parameter(ParameterSetName='UpdateScope')]
[switch]$ExcludeOptionalUpdates,
[Parameter(ParameterSetName='UpdateScope')]
[switch]$IsWsusInfrastructureUpdate,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]$IncludedInstallationState,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]$ExcludedInstallationState,
[Parameter(ParameterSetName='UpdateScope')]
[DateTime]$FromArrivalDate,
[Parameter(ParameterSetName='UpdateScope')]
[DateTime]$ToArrivalDate,
[Parameter(ParameterSetName='UpdateScope')]
[DateTime]$FromCreationDate,
[Parameter(ParameterSetName='UpdateScope')]
[DateTime]$ToCreationDate,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.UpdateApprovalActions]$UpdateApprovalAction,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Administration.UpdateSources]$UpdateSource,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Internal.BaseApi.UpdateCategory[]]$Category,
[Parameter(ParameterSetName='UpdateScope')]
[Microsoft.UpdateServices.Internal.BaseApi.UpdateClassification[]]$Classification
)
Begin {
if($wsus)
{
$ErrorActionPreference = 'stop'
If ($PSCmdlet.ParameterSetName -eq 'UpdateScope') {
$UpdateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
If ($PSBoundParameters['ApprovedState']) {
$UpdateScope.ApprovedStates = $ApprovedState
}
If ($PSBoundParameters['IncludedInstallationState']) {
$UpdateScope.IncludedInstallationStates = $IncludedInstallationState
}
If ($PSBoundParameters['ExcludedInstallationState']) {
$UpdateScope.ExcludedInstallationStates = $ExcludedInstallationState
}
If ($PSBoundParameters['UpdateApprovalAction']) {
$UpdateScope.UpdateApprovalActions = $UpdateApprovalAction
}
If ($PSBoundParameters['UpdateSource']) {
$UpdateScope.UpdateSources = $UpdateSource
}
If ($PSBoundParameters['UpdateType']) {
$UpdateScope.UpdateTypes = $UpdateType
}
If ($PSBoundParameters['FromArrivalDate']) {
$UpdateScope.FromArrivalDate = $FromArrivalDate
}
If ($PSBoundParameters['ToArrivalDate']) {
$UpdateScope.ToArrivalDate = $ToArrivalDate
}
If ($PSBoundParameters['FromCreationDate']) {
$UpdateScope.FromCreationDate = $FromCreationDate
}
If ($PSBoundParameters['ToCreationDate']) {
$UpdateScope.ToCreationDate = $ToCreationDate
}
If ($PSBoundParameters['ExcludeOptionalUpdates']) {
$UpdateScope.ExcludeOptionalUpdates = $ExcludeOptionalUpdates
}
If ($PSBoundParameters['IsWsusInfrastructureUpdate']) {
$UpdateScope.IsWsusInfrastructureUpdate = $IsWsusInfrastructureUpdate
}
If ($PSBoundParameters['Category']) {
[void]$UpdateScope.Categories.AddRange($Category)
}
If ($PSBoundParameters['Classification']) {
[void]$UpdateScope.Classifications.AddRange($Classification)
}
If ($PSBoundParameters['IncludeText']) {
$UpdateScope.TextIncludes = $IncludeText
}
If ($PSBoundParameters['ExcludeText']) {
$UpdateScope.TextNotIncludes = $ExcludeText
}
If ($PSBoundParameters['ComputerTargetGroups']) {
$Groups = @{}
$Wsus.GetComputerTargetGroups() | ForEach {
$Groups[$_.Name]=$_
}
ForEach ($Group in $ComputerTargetGroups) {
Write-Verbose "Adding Target Group: $($Group)"
[void]$UpdateScope.ApprovedComputerTargetGroups.Add($Groups[$Group])
}
}
}
}#endif
else
{
Write-Warning "Use Connect-PSWSUSServer to establish connection with your Windows Update Server"
Break
}
}
Process {
Switch ($PSCmdlet.ParameterSetName) {
'Update' {
ForEach ($Item in $Update) {
Write-Verbose "Searching for $($Update)"
$Wsus.SearchUpdates($Item)
}
}
'UpdateScope' {
$Wsus.getupdates($UpdateScope)
}
'All'{
$Wsus.getupdates()
}
}
}
End {
$ErrorActionPreference = 'continue'
}
}