PowerShell: foreach with a first and last item number

I wanted to work through 1000+ items in a PowerShell foreach loop, but I wanted to do it X at a time. I figured out the following foreach syntax to loop through all items after first and before last:

$First = 15
$Last = 45
foreach ($Row in $Rows | select -first $Last | select -last (($Last - $First)+1)){
. . . .
}

Comments are closed.