BaskervilleByte
Contributor
Contributor

Need help running start-job within loop...

Jump to solution

Hi all,

I have the following script which runs a python script against several domain controllers within our infrastructure (CVE-2020-1472) to test for this vulnerability

The script can take over 10 minutes (or more) to run per DC so running it serial which I did initially can take all day

I have spent some time investigating start-job without much success but time is running out for me to get this completed so I am hoping you guys can help me out?

One of my missing PowerShell skillsets are parameters which I think is probably my issue here as well as my full understanding of how the retrieved data from my scriptblock is played back into the loop

Below is a screenshot of what I receive so far and script attached

Start-JobScreenshot.jpg

Any help would be much appreciated

Many thanks in advance

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You can pass arguments to the code block via the ArgumentList parameter.

A rather simple example

$code = {

    param(

        [int]$Value

    )


    $Value

}


$myValue = 1

$job = Start-Job -ScriptBlock $code -ArgumentList $myValue

Receive-Job -Job $job -Wait


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership

You can pass arguments to the code block via the ArgumentList parameter.

A rather simple example

$code = {

    param(

        [int]$Value

    )


    $Value

}


$myValue = 1

$job = Start-Job -ScriptBlock $code -ArgumentList $myValue

Receive-Job -Job $job -Wait


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos