I have two lists with the same length. I need to iterate so that the first item in the list A matches the first item in the list B. For that I've created a nested foreach loop, that looks like this:
$nodes_table = "a","b","c"
$nodes_list = "a","b","c"
:Outer foreach ($item in $nodes_table) {
foreach($node in $nodes_list)
{
if($node -eq $item)
{
Write-Output "$node hostname matches in vTM"
break :Outer
}
}
}
Problem: In the first iteration, it matches. But in the second iteration, the inner loop doesn't go to the second item, it resets again.
First iteration: $node = a equals $item = a
Second iteration: $node = a not equals to $item = b.
As you can see, in the second iteration inner loop didn't iterate, it reset back to a.
Forloop?For($i=0;$i -lt $nodes_table.count;$i++){"nodes_table: $($nodes_table[$i]) - nodes_list: $($nodes_list[$i])"}