Author Posts

April 26, 2017 at 6:45 pm

Hi,

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?

Cheers

April 26, 2017 at 7:14 pm

You could do it with a workflow

workflow MyStopService
{
     $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.

April 26, 2017 at 8:15 pm

Thanks Paul, the workflow seems to have done the trick.

Cheers