forked from proxb/PoshWSUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-PSWSUSConfigProduct.ps1
122 lines (109 loc) · 3.84 KB
/
Set-PSWSUSConfigProduct.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
function Set-PSWSUSConfigProduct {
<#
.SYNOPSIS
Sets whether the product representing the category of updates to synchronize is enabled or disabled.
.DESCRIPTION
The Set-PSWSUSProduct cmdlet enables or disables the product representing the category of updates to synchronized.
In order to use this cmdlet, the Get-PSWSUSUpdateCategory cmdlet must be run (optionally using the Where-Object cmdlet to
filter its results) with its results piped into this cmdlet.
.PARAMETER Product
Specifies the product for which the updates are to be synchronized. If the Disable parameter is used, then this parameter
specifies the product for which the updates are not to be synchronized. This parameter value is piped from the Get-PSWSUSUpdateCategory cmdlet.
.PARAMETER Disable
Specifies that updates are not to be synchronized for the specified product.
.NOTES
Name: Set-PSWSUSConfigProduct
Author: Dubinsky Evgeny
DateCreated: 10MAY2013]
Modified 05 Feb 2014 -- Boe Prox
-Add -WhatIf support
.EXAMPLE
Get-PSWSUSUpdateCategory | where { $_.Title -in @(
'Office 2010',
'Office 2013',
'Windows 7',
'Windows 8',
'Windows Server 2008 R2',
'Windows Server 2008',
'Windows Server 2012 Language Packs',
'Windows Server 2012',
'Windows XP'
'Silverlight'
)} | Set-PSWSUSConfigProduct
Description
-----------
This command will choose Products that you will synchronize from MS Windows Update.
.EXAMPLE
Get-PSWSUSUpdateCategory | where {$_.Title -eq "Silverlight"} | Set-PSWSUSConfigProduct -Disable
Description
-----------
This command will disable Silverlight product from synchronize with MS Windows Update.
.LINK
http://blog.itstuff.in.ua/?p=62#Set-PSWSUSConfigProduct
#>
[CmdletBinding()]
Param
(
[Parameter(
Mandatory = $True,
Position = 0,
ValueFromPipeline = $True)]
[Microsoft.UpdateServices.Internal.BaseApi.UpdateCategory]$Product,
[Parameter(
Mandatory = $false,
Position = 1,
ValueFromPipeline = $false)]
[switch]$Disable
)
Begin
{
if (-NOT $wsus)
{
Write-Warning "Use Connect-PSWSUSServer to establish connection with your Windows Update Server."
Break
}
if($PSBoundParameters['Disable'])
{
$Collection = $wsus.GetSubscription().GetUpdateCategories()
}
else
{
$Collection = New-Object -TypeName Microsoft.UpdateServices.Administration.UpdateCategoryCollection
}
$Subscription = $wsus.GetSubscription()
}
Process
{
foreach ($ProductObject in $Product)
{
If ($PSCmdlet.ShouldProcess($productobject,'Set Configuration Product')) {
if($PSBoundParameters['Disable'])
{
$ProductTitle = $ProductObject.Title
$ProductType = $ProductObject.Type
if ($Collection.Title -notcontains $ProductTitle)
{
Write-Warning "$ProductType $ProductTitle not enable."
}
else
{
$Product | ForEach {
$Collection.Remove($_)
}
}
}
else
{
$Collection.Add($productobject) | Out-Null
}
}
}
}
End
{
If ($PSCmdlet.ShouldProcess($wsus.ServerName,'Set Configuration Product')) {
$Subscription.SetUpdateCategories($Collection)
$Subscription.Save()
}
}
}