I have a stored procedure that populates some reporting table, does not return any results, and is very expensive. However it completes in 5 minutes when executed using SSMS. When the same stored procedure is executed though PS 3.0 it runs in almost 25 minutes. The condensed code is shown below. The $Connection is defined elsewhere and is already open at this point.
$Command = New-Object Data.OleDb.OleDbCommand
$Command.CommandTimeout = 600
$Command.CommandText = "dbo.usp_extract_exact_target_user @in_all_flg = 1"
$Command.Connection = $Connection
$Command.ExecuteNonQuery()
Can anyone tell me where I'm going wrong, or what could be causing the 5x execution times?
Thanks in advance for help; you can offer.