Powershell For Loop
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
this way you can iterate collection using foreach.
Example
$collection = @(1, 2, 3, 4, 5)
foreach ($i in $collection)
{
Write-Host $i
}
Copy and Try it
Example
"Welcome to powershell world", "hello" ,"world!!" | foreach {$_.toupper()}
Copy and Try it
Lets analysis above statement, powershell consider first three world as array elements then using pipe sign "|"
you can work with array collection, "$_" this collection object and "toupper" is method of that collection object.
So that you can work with that collection, here we are converting charactors into upper case.
Here is the output