Unable to place list of databases prior to selection section in PowerShell

I run that code

$qry = "select * from sys.databases"
$potentialSourceDatabases = @(Invoke-Sqlcmd -ServerInstance $azureSQLServerDNS `
 -Database $azureDatabase -Username $SQLUsername -Password $SQLPassword `
 -Query $qry -QueryTimeout "1200") | select-object -expand Name

$potentialSourceDatabasesTable = @()
$databaseCounter = 1

foreach ($item in $potentialSourceDatabases){
    $itemProperties = @{
        DBNumber = $databaseCounter++
        DBName = $item
    }
    $potentialSourceDatabasesTable += New-Object -TypeName PsObject -Property $itemProperties
}

$potentialSourceDatabasesTable

$sourceDatabaseNumber = Read-Host -Prompt 'Please select the number of the desired source database'
$output = $potentialSourceDatabasesTable | Where-Object{$_.DBNumber -eq $sourceDatabaseNumber}  | select-object -expand DBName
Write-Host "You selected database is $sourceDatabaseNumber with name $output"

and I am getting the following output:

Please select the number of the desired source database: 1

You selected database is 1 with name master

DBNumber DBName


1 master
2 ProdCopy1
3 ProdCopy2

But I expect that the output of the list of the databases will appear before the prompt to select the desired database.

I don't mind if the solution will include the hashtable or another structure formation. I tried using the hastable:

$hashTable = @{}
$counter = 1

foreach ($item in $potentialSourceDatabases)
{
    $hashTable.Add($counter++,$item)
}
$getDatabaseNumber = Read-Host -Prompt 'Select source database number'
Write-Host "You selected database #$getDatabaseNumber $hashTable.Item($getDatabaseNumber)" 

but it returned Select source database number: 1 You selected database #1 System.Collections.Hashtable.Item(1)

Could you please help me to modify the code so that the list of the tables appear prior to the selection section?