title: Calling SQL Server stored procedure from powershell
body: <p>I'm trying to call a SQL Server stored procedure from PowerShell but I always get errors on parameters.</p>
  
  <p>Stored procedure has 8 parameters, all with default values</p>
  
  <pre><code>@simchain   nvarchar
  @idSimulation    int
  @idCompany   varchar
  @modelName  nvarchar
  @simDate    datetime
  @mySim           int
  @statusFloor     int
  @statusCap       int
  </code></pre>
  
  <p>From Management Studio I can call this procedure even without any parameter, so just executing <code>EXEC [dbo].[E_simulations]</code> works.</p>
  
  <p>From PowerShell I create a connection and a command but I always get an error on missing parameters, for example </p>
  
  <blockquote>
    <p>Procedure or function 'E_simulations' expects parameter '@simchain', which was not supplied.</p>
  </blockquote>
  
  <p>Here is my test code (just to test proper execution)</p>
  
  <pre><code>    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection;
      $SqlConnection.ConnectionString = $ConnectionString;
      $SqlCommand = $SqlConnection.CreateCommand();
      $SqlCommand.CommandText = "EXEC [dbo].[E_simulations]";
      $SqlConnection.Open();
      $returnedValue = $SqlCommand.ExecuteNonQuery();
  </code></pre>
  
  <p>Am I missing something?</p>