private/read/Read-UserInstanceSelection.ps1

function Read-UserInstanceSelection
{
    [CmdletBinding(PositionalBinding = $true)]
    param(
        [psobject] $Ec2Instances
    )

    $instanceId = Read-Host 'Enter an instance-id to begin remote session'

    $instanceId = $instanceId.Trim()

    if (-not $instanceId)
    {
        Write-Host 'No instance selected.' -ForegroundColor DarkYellow
    }
    elseif (-not (Test-InstanceId -InstanceId $instanceId -Ec2Instances $Ec2Instances))
    {
        Write-Host 'Invalid instance selection.' -ForegroundColor DarkYellow
        $instanceId = $null
    }
    else
    {
        $instanceInfo = $Ec2Instances.Where({ $_.InstanceId -eq $instanceId })
        $Host.UI.RawUI.WindowTitle = "EC2Remote: $($instanceInfo.InstanceName)"
    }

    return $instanceId
}