PowerShell loop range with steps PowerShell loop range with steps powershell powershell

PowerShell loop range with steps


Simple Google search should have found you this.

for ($i=123; $i -le 323; $i=$i+2 ) {Write-Host $i;}

(Initialize; condition to keep the loop running; iteration)


Using the original approach (Step 2):

(123..323) | % {if( $_ -band 1 ) {$_ }}

Step 3 and greater:

 (123..323) | % {if( !($i++ % 3) ) {$_ }}