I would like to execute a stored procedure from Powershell (v2) against a SQL Server 2008 database. Coming from using C# as my primary language, I'm doing it in that fashion. For example, when I need to run a sproc that doesn't return results, here is what I'm doing now:
$con = new-object System.Data.SqlClient.SqlConnection($connectionString) $cmd = new-object System.Data.SqlClient.SqlCommand("exec MySproc", $con) $con.Open() $cmd.ExecuteNonQuery() $cn.Close()
While perhaps TMTOWTDI, I'd like to know the best way.
I should mention that I'm already familiar with T-SQL and the System.Data namespace. This is really a question about Powershell.