forked from proxb/PoshWSUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-PSWSUSClient.ps1
174 lines (153 loc) · 6.51 KB
/
Get-PSWSUSClient.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
function Get-PSWSUSClient {
<#
.SYNOPSIS
Retrieves information about a WSUS client.
.DESCRIPTION
Retrieves information about a WSUS client.
.PARAMETER Computername
Name of the client to search for. Accepts a partial name. If left blank, then all clients displayed
.PARAMETER IncludedInstallationState
Update installation states to search for
.PARAMETER ExcludedInstallState
Installation states to exclude
.PARAMETER ComputerTargetGroups
List of target groups to search
.PARAMETER FromLastStatusTime
Earliest reported status time
.PARAMETER ToLastStatusTime
Latest last reported status time to search for
.PARAMETER FromLastSyncTime
Earliest last synchronization time to search for
.PARAMETER ToLastSyncTime
Latest last synchronization time to search for
.PARAMETER OSFamily
Operating system family for which to search
.PARAMETER IncludeSubGroups
List of target groups to search
.PARAMETER IncludeDownstreamComputerTargets
Clients of a downstream server, not clients of this server, should be included
.NOTES
Name: Get-PSWSUSClient
Author: Boe Prox
Version History:
1.2 | 18 Feb 2015
-Renamed to Get-PSWSUSClient
-Add multiple parameters
1.0 | 24 Sept 2010
-Initial Version
.LINK
https://learn-powershell.net
.EXAMPLE
Get-PSWSUSClient -Computername "server1"
Description
-----------
This command will search for and display all computers matching the given input.
.EXAMPLE
Get-PSWSUSClient -ToLastSyncTime (Get-Date).AddDays(-30)
Description
-----------
This command will search for and display all computers that have not synced since in the past 30 days.
.EXAMPLE
$Groups = Get-PSWSUSGroup -Name 'Windows Server 2012 R2'
Get-PSWSUSClient -ComputerTargetGroups $Groups
Description
-----------
This command will search for and display all computers that are members of the specified group.
#>
[cmdletbinding(
DefaultParameterSetName = 'AllComputers'
)]
Param(
[Parameter(Position=0,ParameterSetName = 'Computer',ValueFromPipeline = $True)]
[string[]]$Computername,
[Parameter(ParameterSetName='ComputerScope')]
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]$IncludedInstallationState,
[Parameter(ParameterSetName='ComputerScope')]
[Microsoft.UpdateServices.Administration.UpdateInstallationStates]$ExcludedInstallState,
[Parameter(ParameterSetName='ComputerScope')]
[Microsoft.UpdateServices.Internal.BaseApi.ComputerTargetGroup[]]$ComputerTargetGroups,
[Parameter(ParameterSetName='ComputerScope')]
[DateTime]$FromLastStatusTime,
[Parameter(ParameterSetName='ComputerScope')]
[DateTime]$ToLastStatusTime,
[Parameter(ParameterSetName='ComputerScope')]
[DateTime]$FromLastSyncTime,
[Parameter(ParameterSetName='ComputerScope')]
[DateTime]$ToLastSyncTime,
[Parameter(ParameterSetName='ComputerScope')]
[string]$OSFamily,
[Parameter(ParameterSetName='ComputerScope')]
[switch]$IncludeSubGroups,
[Parameter(ParameterSetName='ComputerScope')]
[switch]$IncludeDownstreamComputerTargets
)
Begin {
if($wsus)
{
$ErrorActionPreference = 'Stop'
If ($PSCmdlet.ParameterSetName -eq 'ComputerScope') {
$ComputerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
If ($PSBoundParameters['IncludedInstallationState']) {
$ComputerScope.IncludedInstallationStates = $IncludedInstallationState
}
If ($PSBoundParameters['ExcludedInstallState']) {
$ComputerScope.ExcludedInstallationStates = $ExcludedInstallState
}
If ($PSBoundParameters['FromLastStatusTime']) {
$ComputerScope.FromLastReportedStatusTime = $FromLastStatusTime
}
If ($PSBoundParameters['ToLastStatusTime']) {
$ComputerScope.ToLastReportedStatusTime = $ToLastStatusTime
}
If ($PSBoundParameters['FromLastSyncTime']) {
$ComputerScope.FromLastSyncTime = $FromLastSyncTime
}
If ($PSBoundParameters['ToLastSyncTime']) {
$ComputerScope.ToLastSyncTime = $ToLastSyncTime
}
If ($PSBoundParameters['IncludeSubGroups']) {
$ComputerScope.IncludeSubgroups = $IncludeSubGroups
}
If ($PSBoundParameters['OSFamily']) {
$ComputerScope.OSFamily = $OSFamily
}
If ($PSBoundParameters['IncludeDownstreamComputerTargets']) {
$ComputerScope.IncludeDownstreamComputerTargets = $IncludeDownstreamComputerTargets
}
If ($PSBoundParameters['ComputerTargetGroups']) {
[void]$ComputerScope.ComputerTargetGroups.AddRange($ComputerTargetGroups)
}
}
}#endif
else
{
Write-Warning "Use Connect-PSWSUSServer to establish connection with your Windows Update Server"
Break
}
}
Process {
Switch ($PSCmdlet.ParameterSetName) {
'AllComputers' {
Write-Verbose "Gather all computers in WSUS"
$wsus.GetComputerTargets()
}
'Computer' {
ForEach ($Computer in $Computername) {
Write-Verbose "Retrieve computer in WSUS"
Try {
$wsus.SearchComputerTargets($Computer)
} Catch {
Write-Warning ("Unable to retrieve {0} from database." -f $Computer)
}
}
}
'ComputerScope' {
Write-Verbose "Retrieve computers based on computer scope"
$wsus.GetComputerTargets($ComputerScope)
}
}
}
End {
$ErrorActionPreference = 'Continue'
}
}