I'm trying to use Azure runbooks to start virtual machines with a specified tag. I use powershell workflow so i can start them i parallel.
The code below works, but it always have problem starting one random virtual machine. This is the exception:
Start-AzureRmVM : Collection was modified; enumeration operation may not execute.
CategoryInfo : CloseError: (:) [Start-AzureRmVM], InvalidOperationException
I thought $TaggedResourcesList = @($Resources)
would enumerate the list and make modifications allowed?
workflow StartUpParallel
{
$Resources = Find-AzureRmResource -TagName Startup -TagValue PreWork
$TaggedResourcesList = @($Resources)
Foreach -Parallel ( $vm in $TaggedResourcesList )
{
if($vm.ResourceType -eq "Microsoft.Compute/virtualMachines")
{
Start-AzureRmVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name
}
}
}
Has anyone else had this problem?