40 lines
868 B
PowerShell
40 lines
868 B
PowerShell
function Get-InstanceHostname {
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Gets the hostname for an EC2 instance.
|
|
|
|
.PARAMETER Instance
|
|
[Amazon.EC2.Model.Instance] The instance under inspection.
|
|
|
|
.EXAMPLE
|
|
Get-InstanceHostname -Instance (Get-CurrentInstance)
|
|
|
|
APP1611088
|
|
#>
|
|
|
|
[OutputType([string])]
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNull()]
|
|
[Amazon.EC2.Model.Instance]$Instance
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName)
|
|
|
|
[string] $hostname = ($instance.Tags | Where-Object { $_.Key -eq $Global:AlkamiTagKeyHostName } | Select-Object -First 1).Value
|
|
|
|
if ( [string]::IsNullOrEmpty( $hostname ) ) {
|
|
|
|
Write-Warning ( "{0} : No hostname found for {1}" -f $logLead, $instance.InstanceId )
|
|
$hostname = $null
|
|
|
|
} else {
|
|
|
|
$hostname = $hostname.ToUpperInvariant()
|
|
}
|
|
|
|
return $hostname
|
|
}
|