title: In PowerShell, how do I use Read-Host input to get parameter value
body: <p>I have a script that contains a parameter list of connection strings to some databases. The script does the following things:</p>
  
  <ul>
  <li>Takes a database name as input using "Read-Host"</li>
  <li>Uses the input to meet any of the If/ElseIf conditions and...
  <ul>
  <li>connects to the database</li>
  <li>runs a SQL script to update the db</li>
  </ul></li>
  </ul>
  
  <p>Here is some example code:</p>
  
  <pre><code>param (
  # Connection Strings
    [string] $TestDb1_ConnectStr = "username/pwd@//hostname1:port1/sid1",
    [string] $TestDb2_ConnectStr = "username/pwd@//hostname2:port2/sid2",
    [string] $TestDb3_ConnectStr = "username/pwd@//hostname2:port3/sid3",
    [string] $SQL_Path = "C:\bin\sql"
  )
  
  $Environment = Read-Host "Please enter environment name..."
  
  If ($Environment -eq "TestDb1")
  {
    function Invoke-SqlPlus($file) { (gc $file) | sqlplus $TestDb1_ConnectStr }
    new-alias sql Invoke-SqlPlus
    sql $SQL_Path\$Environment"_sometable.sql"
  }
  ElseIf ($Environment -eq "TestDb2")
  {
    function Invoke-SqlPlus($file) { (gc $file) | sqlplus $TestDb2_ConnectStr }
    new-alias sql Invoke-SqlPlus
    sql $SQL_Path\$Environment"_sometable.sql"
  }
  ElseIf ($Environment -eq "TestDb3")
  {
    function Invoke-SqlPlus($file) { (gc $file) | sqlplus $TestDb3_ConnectStr }
    new-alias sql Invoke-SqlPlus
    sql $SQL_Path\$Environment"_sometable.sql"
  }
  ...
  </code></pre>
  
  <p>I actually have 14 databases that I can connect to and instead of having 14 separate If/ElseIf conditions I want to be able to use the input from Read-Host to pass in the connection string and SQL script. Currently I can use the input to pass in the SQL script but I'm not able to pass in the db connection string. </p>
  
  <p>I want to do something like this:</p>
  
  <pre><code>function Invoke-SqlPlus($file) { (gc $file) | sqlplus $Environment_ConnectStr }
  new-alias sql Invoke-SqlPlus
  sql $SQL_Path\$Environment"_sometable.sql"
  </code></pre>
  
  <p>However, I'm not sure how I can use the input from Read-Host to get the value from the parameter list for the connection string. How can I achieve this?</p>