Line 22 declares a string variable: $results1 = "test|test1|test2"
, and on line 31 you have a "for" loop with no increment: for ( $i = 0; $i -le $results1.length) {
, and on line 32 you have a foreach: foreach ($line in $result1) {
.
$result1 is a scalar not a list, so that foreach on line 32 will run once.
Line 35 if ($line -match "toolpath_group") {
will never be true because the string "test|test1|test" is never going to be equal to "toolpath group". The same is true for the conditional statements on lines 43 and 49.
On lines 40, 44,48 $i++
you're modifying the control variable of the "for" loop on line 31. You shouldn't be doing that.
And because none of the conditions in the "foreach" loop on line 32 will ever be true, the $i for loop control on line 31 will be incremented only on line 48. The loop on line 31 will probably run 16 times (the number of characters in the $results1 variable) and accomplish nothing.
Given all that, I don't know what you're trying to do, but I can't see how that code ever produced anything!