forked from tomtorggler/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-RsToSubVs.ps1
65 lines (58 loc) · 2.71 KB
/
Add-RsToSubVs.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
function Add-RsToSubVs {
<#
.Synopsis
Add a Real Server to one or more sub virtual services on a KEMP load balancer.
.DESCRIPTION
This function calls Send-LBMessage to add a Real Server to sub virtual services.
A filter for the virtual services nickname can be used in order to add the real server
to multiple sub VS matching the filter. Alternatively, the function takes objects returned
from Get-VirtualService and adds the real server to each returned VS.
.EXAMPLE
Add-RsToSubVs -SubVsFilter "Exchange 2013*" -RealServer 192.168.1.1 -Port 443
This example adds RS 192.168.1.1:443 to all sub virutal services matching the name "Exchange 2013*"
.EXAMPLE
Get-VirtualService | Where-Object {$_.nickname -like "Exchange 2013*"} | Add-RsToSubVs -RealServer 192.168.1.1 -Port 443 -Weight 2000
This example adds RS 192.168.1.1:443 to all virtual services returned by Get-VirtualService and the following filter.
Please note: Get-VirtualService returns only sub virtual services, no addtional filtering is done.
.INPUTS
This cmdlet takes input objects from Get-VirtualService
#>
[CmdletBinding(SupportsShouldProcess=$true,
ConfirmImpact='High')]
param(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ParameterSetName='Index')]
[int]
$Index,
[Parameter(Mandatory=$true,
ParameterSetName='NamePrefix')]
[string]
$SubVsFilter,
[Parameter(Mandatory=$true)]
[ipaddress]
$RealServer,
[Parameter(Mandatory=$true)]
[ValidateRange(1,65535)]
[int]
$Port,
[Parameter(Mandatory=$false)]
[ValidateRange(1,65535)]
[int]
$Weight=1000
)
if ($PSCmdlet.ParameterSetName -eq "Index") { Write-Verbose "VS from Pipeline, Index $Index"
if ($pscmdlet.ShouldProcess("VS $Index", "Add RS $RealServer`:$Port")) {
Send-LBMessage -command addrs -ParameterValuePair @{"vs"=$Index ; "rs"=$RealServer; "rsport"=$Port; "weight"=$Weight }
} } else {
Write-Verbose "Getting VS from Filter $SubVsFilter"
$subVSGroup = Get-VirtualService | Where-Object {$_.nickname -like $SubVsFilter -and $_.mastervs -eq 0 -and (-not$_.subvs)}
foreach ($subVs in $subVSGroup) {
if ($pscmdlet.ShouldProcess($subVs.nickname, "Add RS $RealServer`:$Port")) {
Send-LBMessage -command addrs -ParameterValuePair @{"vs"=$subVs.Index ; "rs"=$RealServer; "rsport"=$Port; "weight"=$Weight }
}
}
}
}