title: Powershell SQL SELECT output to variable
body: <p>I am calling a function to query an SQL table.  I only need the results of one cell.
  I am unable to successfully retrieve the cell data into a variable from the function.</p>
  
  <p>For example, If I had a table with the following:</p>
  
  <pre><code>    FeedID    Name    Address
      15        Bill    Jones
  </code></pre>
  
  <p>I would need to capture the FeedID value of '15' into a variable.
  My SQL statement is only capturing the FeedID but I don't know how to extract the value</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>    function Invoke-SQL {
      param(
      [string] $dataSource = "10.0.100.1",
      [string] $database = "Database123",
      [string] $sqlCommand = $("SELECT [FeedID] FROM [dbo].[FeedList] WHERE [FeedFileName] = 'filename.txt'")
      )
  
      $connectionString = "Data Source=$dataSource; " + "Integrated Security=SSPI; " + "Initial Catalog=$database"
      $connection = new-object system.data.SqlClient.SQLConnection($connectionString)
      $command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
      $connection.Open()
  
      $adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
      $dataset = New-Object System.Data.DataSet
      write-output $adapter.Fill($dataSet) | Out-Null
  
      $connection.Close()
      $dataSet.Tables
      }
  
      $FeedID = Invoke-SQL
      $FeedID
  </code></pre>