this way you can iterate list/collection using for.
Example
for ($i = 0; $i -lt $myLists.Count; $i++) { $list = $myLists[$i]; # ... }
Copy and Try it
$collection = @(1, 2, 3, 4, 5) foreach ($i in $collection) { Write-Host $i }
Putting the lines in a single string
$lines = '' for ($i=0; $i -lt 5; $i++) { $lines += "The current value of i is $i`n" } $lines