You can see Jobs or runspaces . Here is an example of Work:
$block = {
Param([string] $file)
"[Do something]"
}
Get-Job | Remove-Job
$MaxThreads = 4
foreach($file in $files){
While ($(Get-Job -state running).count -ge $MaxThreads){
Start-Sleep -Milliseconds 3
}
Start-Job -Scriptblock $Block -ArgumentList $file
}
While ($(Get-Job -State Running).count -gt 0){
start-sleep 1
}
foreach($job in Get-Job){
$info= Receive-Job -Id ($job.Id)
}
Get-Job | Remove-Job
In the above code, I have it, where each one $fileworks in parallel with eachother (up to 4 starts simultaneously).
EDIT: . , , , PowerShell {}.