The PowerShell’s way of executing parallel instructions has been somewhat complicated till now using Jobs, Runspaces, etc. With PowerShell 7 and above, the team has greatly simplified this requirement with improvement in ForEach-Object
cmdlet. You would need two extra parameters: Parallel and Throttlelimit to execute a set of instructions in parallel.
The Parallel
parameter specifies the script block that is run in parallel for each input item. The new ThrottleLimit
parameter limits the number of script blocks running in parallel at a given time. The default is 5.