title: Check row existence in SQL Server with PowerShell
body: <p>Actually I am dealing for my first time with <strong>PowerShell</strong> scripting.</p>
  
  <p>By looking for a good solution in order to perform a <code>SELECT</code> on <strong>SQL Server</strong>, I found the code as follows:</p>
  
  <pre><code>Function IdentityProviderExistsDatabase {
      param(
          [string] $IdPIdentifier
      )
  
      $SQLQuery = $("SELECT [*] FROM [dbo].[IdPs] WHERE [IdPIdentifier] = '$IdPIdentifier'")
  
      $SQLConnect = new-object system.data.sqlclient.sqlconnection  
      $SQLConnect.connectionstring = $SQLConnectionString
  
      $SQLConnect.Open()  
  
      $command = New-object system.data.sqlclient.SqlCommand   
      $command.connection = $SQLConnect  
      $command.CommandText = $SQLQuery
      $Reader = $command.ExecuteReader()
      while ($Reader.Read()) {
          $Reader.GetValue($1)
      }
  }
  </code></pre>
  
  <p>The solution above works fine, but really I don't need to read any value; for my purposes, I'd just know if the query returns something, thus just if the record exists or not according to the <code>WHERE</code> clause. </p>
  
  <p>Is there a way to perform this operation in a more elegant way than by checking the returned values inside the loop?</p>