I am cloning VMs on ESX server from template. Simplified code looks like this:
Workflow Create-VM {
$List = 1..500
foreach -parallel ($Elem in $List)
{
# Create VM ...
# Configure created VM ..
}
}
Create-VM
Parallel execution is really helpful. Unfortunately in this case doesn't work pretty well. Too many parallel request are generated. I need to limit number of parallel execution to smaller number (for example 4).
I was trying to change 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
There is an option to limit the number of parallel processes in a foreach-parallel loop using -throttlelimit N
. It's great for reducing the parallelism, but if you try a high number the system may still limit you to 5, depending on all your software versions (YAY! Microsoft consistency). I know the question is old, but since it came up on Google without a decent answer, I thought I'd chime in.
Workflow Create-VM {
$List = 1..500
foreach -parallel -throttlelimit 4 ($Elem in $List)
{
# Create VM ...
# Configure created VM ..
}
}
Create-VM