146 lines
4.5 KiB
PowerShell
146 lines
4.5 KiB
PowerShell
|
function Get-ArmorList {
|
||
|
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Retrieve hostnames for an environment in a usable format.
|
||
|
|
||
|
.DESCRIPTION
|
||
|
A script that allows the user to retrieve all or some of the hosts in an environment, properly formatted for addition to an armor file, or for use in other applications.
|
||
|
|
||
|
.PARAMETER EnvironmentName
|
||
|
Required Parameter. The moniker associated with the environment (e.g. '12.4', 'Smith')
|
||
|
|
||
|
.PARAMETER EnvironmentType
|
||
|
Optional Parameter. The type of environment (e.g. 'prod', 'dr'). Defaults to the environment of the server the command is run from.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod'
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
APP16115197.fh.local,APP167765.fh.local,APP1697110.fh.local,MIC1676159.fh.local,MIC169629.fh.local,WEB16118134.fh.local,WEB1671254.fh.local,WEB1698191.fh.local
|
||
|
|
||
|
.PARAMETER Tier
|
||
|
Optional Parameter. Filter to a specific tier: App, Web, Mic, Fab. Defaults to include all tiers if not provided.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod' -Tier 'Web'
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
WEB16118134.fh.local,WEB1671254.fh.local,WEB1698191.fh.local
|
||
|
|
||
|
.PARAMETER Quote
|
||
|
Optional Parameter. Wraps each hostname in doublequotes.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod' -Tier 'App' -Quote
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
"APP16115197.fh.local","APP167765.fh.local","APP1697110.fh.local"
|
||
|
|
||
|
.PARAMETER NoDomain
|
||
|
Optional Parameter. Omits the domain name from the hostnames.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod' -Tier 'App' -NoDomain
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
APP16115197,APP167765,APP1697110
|
||
|
|
||
|
.PARAMETER List
|
||
|
Optional Parameter. Returns an array of hostnames instead of a comma-delimited string.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod' -Tier 'App' -List
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
APP16115197.fh.local
|
||
|
APP167765.fh.local
|
||
|
APP1697110.fh.local
|
||
|
|
||
|
.PARAMETER IncludeOffline
|
||
|
Optional Parameter. Returns both offline and online hosts.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 12.4 -EnvironmentType 'Prod' -Tier 'App' -IncludeOffline
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
APP16111223.fh.local,APP16115197.fh.local,APP16122230.fh.local,APP167765.fh.local,APP1697110.fh.local
|
||
|
|
||
|
.PARAMETER ProfileName
|
||
|
Optional Parameter. Specify the AWS profile to use.
|
||
|
|
||
|
.PARAMETER Region
|
||
|
Optional Parameter. Specify the AWS region to use.
|
||
|
|
||
|
.EXAMPLE
|
||
|
Get-ArmorList -EnvironmentName 17 -EnvironmentType 'Prod' -Tier 'App' -ProfileName 'temp-prod' -Region 'us-west-2'
|
||
|
|
||
|
[Get-DesignationTagNameByEnvironment] : Checking designation value for environment Prod
|
||
|
APP3210599.fh.local,APP3272118.fh.local,APP327852.fh.local
|
||
|
#>
|
||
|
|
||
|
[CmdletBinding()]
|
||
|
param (
|
||
|
[Parameter(Mandatory = $true)]
|
||
|
[ValidateNotNullOrEmpty()]
|
||
|
[Alias("Pod")]
|
||
|
[string]$EnvironmentName,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[string]$EnvironmentType,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[ValidateSet("web", "app", "mic", "fab")]
|
||
|
[string]$Tier,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[Switch]$Quote,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[Switch]$NoDomain,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[Switch]$List,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[Switch]$IncludeOffline,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[string]$ProfileName = $null,
|
||
|
|
||
|
[Parameter(Mandatory = $false)]
|
||
|
[string]$Region = $null
|
||
|
)
|
||
|
|
||
|
[string[]] $servers = Get-HostnamesByEnvironmentName -EnvironmentName $EnvironmentName -EnvironmentType $EnvironmentType `
|
||
|
-ProfileName $ProfileName -Region $Region -IncludeOffline:$IncludeOffline
|
||
|
|
||
|
if ( ! $NoDomain ) {
|
||
|
|
||
|
$servers = foreach ( $server in $servers ) {
|
||
|
|
||
|
"$server.fh.local"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( $PSBoundParameters.ContainsKey('Tier') ) {
|
||
|
|
||
|
[string[]] $servers = Get-ServerByType -Server $servers -Type $Tier
|
||
|
}
|
||
|
|
||
|
if ( $Quote ) {
|
||
|
|
||
|
$servers = foreach ( $server in $servers ) {
|
||
|
|
||
|
"`"$server`""
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( ! $List ) {
|
||
|
|
||
|
$servers = $servers -join ','
|
||
|
}
|
||
|
|
||
|
return $servers
|
||
|
}
|