> $array = @("item1", "item2", "item3") > for($i = 0; $i -lt $array.length; $i++){ $array[$i] } item1 item2 item3
foreach ($item in $items) { ## Do something to each item }
> $array = @("item1", "item2", "item3") > foreach ($element in $array) { $element } item1 item2 item3 > $array | foreach { $_ } item1 item2 item3
ForEach-Object [-InputObject <PSObject>] [-Begin <ScriptBlock>] [-Process] <ScriptBlock[]> [-End <ScriptBlock>] [-RemainingScripts <ScriptBlock[]>] [-WhatIf] [-Confirm] [<CommonParameters>]