-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFindEndpointToUse.ps1
82 lines (82 loc) · 3.74 KB
/
FindEndpointToUse.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
function FindEndpointToUse
{
[cmdletbinding()]
param
(
[parameter()]
[AllowNull()]
$EndpointIdentity
,
$ServiceObject
,
$EndpointGroup
,
[parameter()]
[ValidateSet('Admin', 'MRS')]
$EndpointType = 'Admin'
)
$FilteredEndpoints = @(
switch ($null -eq $EndpointIdentity)
{
$false
{
#Write-verbose -Message "Endpoint Identity was specified. Return only that endpoint."
if ($EndpointIdentity -notin $ServiceObject.Endpoints.Identity)
{throw("Invalid Endpoint Identity $EndpointIdentity was specified. System $($ServiceObject.Identity) has no such endpoint.")}
else
{
$ServiceObject.Endpoints | Where-Object -FilterScript {$_.Identity -eq $EndpointIdentity}
}
}
$true
{
#Write-verbose -message "Endpoint Identity was not specified. Return all applicable endpoints, with preferred first if specified."
switch ($null -eq $ServiceObject.PreferredEndpoint)
{
$false
{
#Write-Verbose -Message "Preferred Endpoint is specified."
$PreEndpoints = @(
switch ($null -eq $EndpointGroup)
{
$true
{
#Write-Verbose -message 'EndpointGroup was not specified'
$ServiceObject.Endpoints | Where-Object -FilterScript {$_.EndpointType -eq $EndpointType} | Sort-Object -Property Precedence
}#end false
$false
{
#Write-Verbose -message 'EndpointGroup was specified'
$ServiceObject.Endpoints | Where-Object -FilterScript {$_.EndpointType -eq $EndpointType -and $_.EndpointGroup -eq $EndpointGroup} | Sort-Object -Property Precedence
}#end true
}#end switch
)
$PreEndpoints | Where-Object {$_.Identity -eq $ServiceObject.PreferredEndpoint} | ForEach-Object {$_.Precedence = -1}
$PreEndpoints
}#end false
$true
{
#Write-Verbose -Message "Preferred Endpoint is not specified."
switch ($null -eq $EndpointGroup)
{
$true
{
#Write-Verbose -message 'EndpointGroup was not specified'
$ServiceObject.Endpoints | Where-Object -FilterScript {$_.EndpointType -eq $EndpointType} | Sort-Object -Property Precedence
}#end false
#EndpointGroup was specified
$false
{
#Write-Verbose -message 'EndpointGroup was specified'
$ServiceObject.Endpoints | Where-Object -FilterScript {$_.EndpointType -eq $EndpointType -and $_.EndpointGroup -eq $EndpointGroup} | Sort-Object -Property Precedence
}#end true
}#end switch
}#end true
}#end switch
}#end $true
}#end switch
)
$GroupedEndpoints = @($FilteredEndpoints | Group-Object -Property Precedence)
$GroupedEndpoints
}
#end function Find-EndpointToUse