title: Get count of rows from MSSQL database with Powershell
body: <p>I'm trying to get the number of rows from a Microsoft SQL database table in Powershell as an integer and am stuck peeling the figure out of the object Powershell is returning.</p>
  
  <p>I have;</p>
  
  <pre><code>$SQLServer = "MSSQL01"   $SQLDBName = "TheTable" $SqlQuery = "select count(*) from cases where opened_date =&lt; '2014-07-30'"
  
  $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
  
  $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = $SqlQuery $SqlCmd.Connection = $SqlConnection
  
  $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SqlCmd
  
  $DataSet = New-Object System.Data.DataSet $SqlAdapter.Fill($DataSet)
  
  $SqlConnection.Close()
  </code></pre>
  
  <p>Now $DataSet.Tables[0] in this instance returns an object like;</p>
  
  <pre><code>Table Name
  -----------
  
  45
  </code></pre>
  
  <p>How can I grab just the 45 as an int?</p>