$num = gc 8.txt function product() { BEGIN { [int]$prod = 1 } PROCESS { #write-host 'prod ' $prod $prod *= [int][string]$_ #write-host $_ $prod } END { $prod } } $max = 0 for ($i=0; $i -lt $num.length - 5; $i++) { $curr = $num[$($i)..$($i+4)] | product if ($curr -gt $max) { $max = $curr } } $max