title: How to call a stored procedure with a char parameter from Powershell
body: <p>I have a Powershell script which I want to execute a SQL Server stored procedure. The stored procedure has a parameter named <code>@backupType</code> which of a <code>CHAR(1)</code> type. I'm calling it like this:</p>
  
  <pre><code>$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  $SqlConnection.ConnectionString = "Server=(local);Database=master;Integrated Security=True"
  $SqlConnection.Open()
  $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  $SqlCmd.CommandText = "sp_myStoredProcedure"
  $SqlCmd.Connection = $SqlConnection
  
  $SqlCmd.Parameters.Add("@backupType", [System.Data.SqlDbType]"Char", 1)
  $SqlCmd.Parameters["@backupType"].Value = "F"
  
  $result = $SqlCmd.ExecuteNonQuery()
  $SqlConnection.Close()
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>Exception calling "ExecuteNonQuery" with "0" argument(s): "Procedure or function 'sp_myStoredProcedure' expects  parameter '@backupType', which was not supplied." At line:14 char:1</p>
    
    <ul>
    <li>$result = $SqlCmd.ExecuteNonQuery()  </li>
    <li>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    
    <ul>
    <li>CategoryInfo          : NotSpecified: (:) [], MethodInvocationException  </li>
    <li>FullyQualifiedErrorId : SqlException  </li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>I can only assume I'm specifying the parameter wrong but a Google and search of SO has not surfaced anything helpful. Any ideas?</p>