Open janegilring opened 6 years ago
Nice catch!
Indeed there is a collection modification inside a foreach
loop
The simplified version of this code is:
Foreach($runspace in $runspaces) {
...
$temphash = $runspaces.clone()
$temphash | Where-Object { $_.runspace -eq $Null } | ForEach-Object {
$Runspaces.remove($_)
}
...
}
UPD: nevermind, it happens outside of this loop, it should be something else...
I am leveraging Invoke-Parallel to process VM actions in parallel in an Azure Automation runbook:
This works as expected, however, the following error is generated in the error stream: Get-RunspaceData : Collection was modified; enumeration operation may not execute. At Invoke-Parallell 542 char:13
Any idea what might be causing this?