Welcome › Forums › General PowerShell Q&A › Process all objects in Foreach
This topic contains 2 replies, has 2 voices, and was last updated by
Is it possible to process all objects in a foreach loop without waiting for the previous object to complete?
So for instance
$Services = Get-Service
Foreach ($Service in $Services)
Stop-Service -Name $Service.
Is there a way to do all in one hit?
You could do it with a workflow
$services = get-service
foreach -parallel ($service in $services)
stop-service -name $service
Now this doesn't do anything about services that stop one service when stopping themselves – but this is at least one way you could accomplish what you were looking to do.
Thanks Paul, the workflow seems to have done the trick.
The topic ‘Process all objects in Foreach’ is closed to new replies.