Powershell 3.0 - Workflows - Concurrency Limit

I am cloning virtual machines on an ESX server from a template. The simplified code is as follows:

Workflow Create-VM {
  $List = 1..500
  foreach -parallel ($Elem in $List)
  {
      # Create VM ...
      # Configure created VM ..
  }
}

Create-VM

Parallel execution is really useful. Unfortunately, in this case this does not work very well. Too many concurrent queries generated. I need to limit the parallel execution number to a smaller number (e.g. 4).

I tried to change the local session configuration (SessionThrottleLimit, MaxSessionsPerWorkflow, MaxRunningWorkflows) http://technet.microsoft.com/en-us/library/hh849862.aspx .

$WWE = New-PSWorkflowExecutionOption  -SessionThrottleLimit 4
Set-PSSessionConfiguration -Name microsoft.powershell.workflow `
   -SessionTypeOption $WWE 
Get-PSSessionConfiguration microsoft.powershell.workflow | 
fl SessionThrottleLimit

Question

  • What parameter (or combination) of the session configuration should be changed to limit the number of concurrent operations to 4?
  • - , (: ...)?
+5
3

foreach-parallel, -throttlelimit N. parallelism, , 5, ( YAY! Microsoft). , , Google , , .

Workflow Create-VM {
  $List = 1..500
  foreach -parallel -throttlelimit 4 ($Elem in $List)
  {
      # Create VM ...
      # Configure created VM ..
  }
}

Create-VM
+9

, foreach. ,

Workflow Create-VM {
  $List = 1..500
  # Calclulate indexes to get elements 0,3; 4,7; 8,11 and so on
  # Use the .. operator to extract those elements from $list and pass
  # 'em to foreach -parallel processing part
  for($i=0;$i -le $List.Count-4; $i+=4) { 
    foreach -parallel ($Elem in $list[$i..($i+3)]) {
      # Create VM ...
      # Configure created VM ..
    } 
  }
}
+3

Just wanted to add this detail, the ThrottleLimit switch mentioned above is available in Powershell v4.0, it is not in version 3.0. We have a mix of 2.0 and 3.0 servers.

0
source

All Articles