PS 7.0 just got support for parallel execution in ForEach-Object cmdlet

Old way:

> Measure-Command {1..50 | ForEach-Object {Start-Sleep -Milliseconds (Get-Random -Minimum 100 -Maximum 200); $_}} Days : 0 Hours : 0 Minutes : 0 Seconds : 8 Milliseconds : 145 Ticks : 81455266 TotalDays : 9.42769282407407E-05 TotalHours : 0.00226264627777778 TotalMinutes : 0.135758776666667 TotalSeconds : 8.1455266 TotalMilliseconds : 8145.5266 

Vs new way:

> Measure-Command {1..50 | ForEach-Object -Parallel {Start-Sleep -Milliseconds (Get-Random -Minimum 100 -Maximum 200); $_}} Days : 0 Hours : 0 Minutes : 0 Seconds : 2 Milliseconds : 94 Ticks : 20947062 TotalDays : 2.42442847222222E-05 TotalHours : 0.000581862833333333 TotalMinutes : 0.03491177 TotalSeconds : 2.0947062 TotalMilliseconds : 2094.7062 

submitted by /u/bukem
[link] [comments]

Leave a Reply