locked
Execute concurrent processes using PowerShell RRS feed

  • Question

  • Hello Experts,

    I would like to setup a new PowerShell script that invokes my Database Stored Procedure concurrently. I am currently having a Control table that has a Job_ID column and a Code column. There might be more than one Job_ID for a code value in the Control table. Based on the code value I pass in the PowerShell along with a date, I would like the PowerShell to trigger the Stored Procedure which is expecting "Job_ID" and "MyDate" as input parameters.

    FYI, I am using PowerShell and SQL Server 2016.

    PS C:\PowerShell> $PSVersionTable.PSVersion
    
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    2      0      -1     -1

    Here is some sample data for your reference:

    CREATE TABLE control_table(JOB_ID INT, CODE VARCHAR(5));
    INSERT INTO control_table(1, 'ABC');
    INSERT INTO control_table(2, 'ABC');
    INSERT INTO control_table(3, 'ABC');
    INSERT INTO control_table(1, 'DEF');
    INSERT INTO control_table(1, 'GHI');
    
    CREATE PROCEDURE myschema.run_job (@JOB_ID INT, @MyDate DATE)
    AS
    BEGIN
    -- Do Something
    END

    When I run the PowerShell script by passing 'ABC" as code, it should execute all the three jobs concurrently by reading the control table.

    Something like

    .\test.ps1 –MyCode “ABC” –Dt “12/27/2018”

    Thanks!

    Known is a DROP, Unknown is an OCEAN.


    • Edited by Bangaaram Wednesday, January 2, 2019 4:22 PM
    Wednesday, January 2, 2019 4:22 PM

Answers

  • Hi jrv, I apologize for overlooking the technet vs MSDN. I have posted my question in the respective forum based on your suggestion. I hope to get the help from there. Thank you!

    Known is a DROP, Unknown is an OCEAN.

    • Marked as answer by jrv Wednesday, January 2, 2019 6:22 PM
    Wednesday, January 2, 2019 5:29 PM

All replies

  • Post your code.  We cannot answer a vague question that includes no code example with any errors.

    Please carefully review the following links to set your expectation for posting in  technical forums.

    This Forum is for Scripting Questions Rather than script requests


    \_(ツ)_/

    Wednesday, January 2, 2019 4:57 PM
  • Hi jrv, I have no code and I am newbie to PowerShell and that is why I am seeking help here like any MSDN forum with the requirements. 

    Known is a DROP, Unknown is an OCEAN.

    Wednesday, January 2, 2019 5:06 PM
  • Hi jrv, I have no code and I am newbie to PowerShell and that is why I am seeking help here like any MSDN forum with the requirements. 

    Known is a DROP, Unknown is an OCEAN.

    This is not an MSDN forum.  It is a TechNet forum and we do not write scripts based on requirements.  You must be writing PS scripts and have a question about your script.  Also your requirements are totally ambiguous and cannot be used to even guess at what you are asking to do.

    I can recommend starting by acquiring the SQLServer module and then learning how to use it for  the help. TO understand how to execute and manage SQLServer tables and procedures you will need to post in the SQLServer forum which has a PowerShell specific sub-forum.

    To get and use the module you will need to upgrade PS to WMF 5.1 and then install the module:

    Install-Module SqlServer

    See: https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module?view=sql-server-2017


    \_(ツ)_/

    Wednesday, January 2, 2019 5:14 PM
  • Hi jrv, I apologize for overlooking the technet vs MSDN. I have posted my question in the respective forum based on your suggestion. I hope to get the help from there. Thank you!

    Known is a DROP, Unknown is an OCEAN.

    • Marked as answer by jrv Wednesday, January 2, 2019 6:22 PM
    Wednesday, January 2, 2019 5:29 PM
  • Thank you.  If you get a script written and have specific issues with the PowerShell language or how to structure a program then you can post here.  For product specific issues always start in the product forum for the target product and check if they have a PS sub-forum.  This will get you a much faster and more targeted answer.


    \_(ツ)_/

    Wednesday, January 2, 2019 5:34 PM
  • I'm trying out this different way.  It can output to the console, but you need stop-process to kill the extra powershell.exe instance.

    start-process powershell -NoNewWindow -ArgumentList '-file .\loop.ps1'


    loop.ps1 is:


    while (1) { echo hi; sleep 5 }


    Stop it:


    get-process powershell | select -last 1 | stop-process

    • Edited by JS2010 Wednesday, January 2, 2019 6:17 PM
    Wednesday, January 2, 2019 6:11 PM