45 lines
1.4 KiB
PowerShell
45 lines
1.4 KiB
PowerShell
function Get-ServicesByTier {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns service names belonging to the specified tier and optionally lower
|
|
|
|
.PARAMETER Tier
|
|
[-Tier] <int> - Returns a <string[]> containing names of tiered services categorized
|
|
under the provided numbered tier.
|
|
|
|
.PARAMETER IncludeLowerTiers
|
|
[-IncludeLowerTiers] - Also include services from all tiers lower than the provided tier.
|
|
(With this swtich present, -Tier 0 returns only tier 0 service names, 1 returns both tier 0 and 1 services, 2 returns
|
|
tier 2, 1, and 0, ad infinitum.) Values provided above the number of defined tiers simply returns all available tiered services.
|
|
#>
|
|
[CmdletBinding()]
|
|
[OutputType([System.Object])]
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateRange(0, [int]::MaxValue)]
|
|
[int]$Tier,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[switch]$IncludeLowerTiers
|
|
)
|
|
|
|
$tiers = Get-MicroserviceTiers
|
|
|
|
#Only return a single tier if switch is not present
|
|
if (!($IncludeLowerTiers.IsPresent)) {
|
|
return $tiers[$Tier]
|
|
}
|
|
|
|
$currentTier = 0
|
|
$services = @()
|
|
foreach ($servicesArray in $tiers) {
|
|
if ($currentTier++ -le $Tier) { #Tip: ++ happens _after_ evaluation when it's on the right
|
|
$services += $servicesArray
|
|
}
|
|
else {
|
|
break
|
|
}
|
|
}
|
|
|
|
return $services
|
|
} |