forked from proxb/PoshWSUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-PSWSUSGroup.ps1
98 lines (87 loc) · 2.93 KB
/
New-PSWSUSGroup.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
function New-PSWSUSGroup {
<#
.SYNOPSIS
Creates a new WSUS Target group.
.DESCRIPTION
Creates a new WSUS Target group.
.PARAMETER Name
Name of group being created.
.PARAMETER ParentGroup
Parent group to add child group to.
.PARAMETER PassThru
.NOTES
Name: New-PSWSUSGroup
Author: Boe Prox
DateCreated: 24SEPT2010
.LINK
https://learn-powershell.net
.EXAMPLE
New-PSWSUSGroup -name "TestGroup"
Description
-----------
This command will create a new Target group called 'TestGroup'
.EXAMPLE
Get-PSWSUSGroup -Name 'Domain Servers' | New-PSWSUSGroup -name "TestGroup"
Description
-----------
This command will create a new Target group called 'TestGroup' under the parent group 'Domain Servers'
#>
[cmdletbinding(
DefaultParameterSetName = 'group',
ConfirmImpact = 'low',
SupportsShouldProcess = $True
)]
Param(
[Parameter(
Mandatory = $True,
Position = 0,
ParameterSetName = '',
ValueFromPipeline = $True)]
[string]$Name,
[Parameter(
Mandatory = $False,
Position = 1,
ParameterSetName = 'parentgroup',
ValueFromPipeline = $True)]
[Microsoft.UpdateServices.Internal.BaseApi.ComputerTargetGroup]$ParentGroup,
[Parameter(
Mandatory = $False,
Position = 2)]
[switch]$PassThru
)
Begin {
if(-not $wsus)
{
Write-Warning "Use Connect-PSWSUSServer to establish connection with your Windows Update Server"
Break
}
}
Process {
Try {
#Determine action based on Parameter Set Name
Switch ($pscmdlet.ParameterSetName) {
"group" {
Write-Verbose "Creating computer group"
If ($pscmdlet.ShouldProcess($Name)) {
#Create the computer target group
$Group = $wsus.CreateComputerTargetGroup($Name)
}
}
"parentgroup" {
Write-Verbose "Creating computer group"
If ($pscmdlet.ShouldProcess($Name)) {
#Create the computer target group
$Group = $wsus.CreateComputerTargetGroup($Name,$parentgroup)
}
}
}
} Catch {
Write-Warning ("{0}" -f $_.Exception.Message)
}
}
End {
If ($PSBoundParameters['PassThru']) {
Write-Output $Group
}
}
}