Naveen
Naveen

Reputation: 322

start-job to run script parallelly

Please help , really very much worried How to transform the below script using start-job , I have 6 Modules to compare , but sequentially it's taking too much time I am trying to adopt start-job option so that I can run this compare parallelly or in background

Tried this -

Start-Job -Name "Comparecontrol" -filepath $ExecuteSbtWithDcmDm -ArgumentList $CompareControl,"",$false,$false | Out-Null
echolog $THISSCRIPT $DCM_UPDATE_LOG_FILE $LLINFO "Finished Control Master Comparison

Main Script

Upvotes: 1

Views: 265

Answers (1)

Keith Hill
Keith Hill

Reputation: 201662

The general flow would be something like this:

$jobs = @()
$jobs += Start-Job -scriptblock {...}
...
$jobs += Start-Job -scriptblock {...}
Wait-Job $jobs
$results = Receive-Job $jobs

You can use a job name as an alternative to storing the job instance returned by Start-Job e.g.:

$jobName = 'CompareControl'
foreach ($script in $scripts)
{
    Start-Job -Name $jobName-scriptblock {&$script} -ArgumentList ...
}
Wait-Job -Name $jobName
$results = Receive-Job -Name $jobName

Upvotes: 3

Related Questions