Parallel execution

When you are confident that you have really eked out the maximum performance from your ForEach loop, there might still be room for improvement through parallelization. Usually, your beefy developer/operations machine laughs at your scripts, so you might as well use some more CPU cycles and some additional memory.

The most common approach to parallelization is to use the job cmdlets and work with the System.Management.Automation.Job objects. This yields good results but requires you to manage the jobs and their output properly. You will not be able to change variables in your scope from within your running jobs.

When working remotely in Invoke-Command, parallelization happens out of the box. This can be controlled by modifying ...

Get Learn PowerShell Core 6.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.