< Back
You are here:
Print

Passing an array to background jobs

One issue you might encounter when using background jobs is how to pass parameters to these jobs. And more specifically arrays.

The issue is that all values on ArgumentList are passed as one array to the code block of the Start-Job cmdlet. The trick is to to present your array as one value to the background job. This can be done through the array notation with (,$myArray).

An example

If you need to pass multiple arguments, you can add these on the ArgumentList parameter. Like this.

This also works when you need to pass multiple arrays to the background job.

Next Running a background job

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Table of Contents