Execute concurrent processes using PowerShell

Welcome Forums General PowerShell Q&A Execute concurrent processes using PowerShell

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
2 weeks, 4 days ago.

  • Author
    Posts
  • #132363

    Participant
    Points: 14
    Rank: Member

    Hello Experts,

    I am a newbie to PowerShell and trying to a build a script that does the following functionality. Could someone please help me with this?

    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 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
  • #132410

    Participant
    Points: 282
    Helping Hand
    Rank: Contributor

    Hi Julaayi,

    Please refer my blog post below, and you can use or customize as per your requirement...

    SQL Server PSObject – Working with SQL Server using PowerShell

    Thank you.

     

  • #132617

    Participant
    Points: 14
    Rank: Member

    Hi Kiran,

    Thank you for the reply. I couldn't find scripts that does asynchronous processing or run jobs concurrently. Please advise.

  • #132650

    Participant
    Points: 282
    Helping Hand
    Rank: Contributor

    Hi Julaayi – Can you put down your code? So that I can tweak it a bit as per your requirement. Thank you.

You must be logged in to reply to this topic.