2020-06-17T22:32:32+00:00
Here's a cool way to visualize runspaces and how they work asynchronously.
$IndentLevel = 2
Get-Random; @(1..100) | ForEach-Object -Parallel {
$i = $_
Start-Sleep -Milliseconds (Get-Random -Minimum 100 -Maximum 1500)
"{0,$($i * $using:IndentLevel)}" -f $i | Write-Host
}
The random delay can help show how some tasks finish out of order. For example, running that might result in this in the console: