Pass parameter to SQL Server stored procedure in Powershell

Christopher Jack 1,611 Reputation points
2021-02-09T10:10:58.327+00:00

Hi,

I have the following code.

$SqlCmd.CommandText = $("EXEC [ZoomFS].[ReboundHeader] @SalesDocNum = $comps[i] ");

The error I am receiving is

Exception calling "Fill" with "1" argument(s): "Could not find stored procedure ''."ps1:55 char:1

  • $SqlAdapter.Fill($DataSet);
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  • FullyQualifiedErrorId : SqlException

I dont think the syntax is correct.

Any help appreciated.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,372 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

2 answers

Sort by: Newest
  1. Jason Kohlhoff 21 Reputation points
    2021-02-11T16:20:13.127+00:00

    @Christopher Jack The following stackoverflow post should help you pass parameters and fill a SqlDataAdapter.

    https://stackoverflow.com/questions/15340496/pass-parameters-from-powershell-to-stored-procedure

    1 person found this answer helpful.

  2. Mico Mi 1,921 Reputation points
    2021-02-10T07:19:44.193+00:00

    Hi,
    Powershell scripts for specific products, such as SQL or Exchange, are out of the scope of WS PS support. Appreciate your understanding.

    Thanks for your time!
    Best Regards,
    Mico Mi

    -----------------------------

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.