Let's say I have a text file containing all county names of any state and I want to process those in groups of 5 until I have exhausted the entire file for purposes of sending that list of 5 to one http call. It would be < 5 if file contains any remainders after dividing total count by 5.
For those 5, I need to construct an http string and once it has processed 5 counties, execute it, then the next 5 and next 5 until the file has < 5 left and then construct the final http line with < 5 in it or if file has perfect multiple of 5, that last http line of < 5 won't be needed (e.g., if remainder has 0 in it after dividing total counties in file by 5.
I can get total quotient and remainder by:
$remainder=$null
$batch=5
$counties=Get-Content "counties.txt"
$quotient=[system.math]::DivRem($counties.count,$batch,[ref] $remainder)
My http string for all quotient groups would look like:
http://somesite&county=<county1>&county=<county2>&county=<county3>&county=<county4>&county=<county5>
If I have a number of counties that is not a perfect multiple of 5, I would have to deal with the remainder of division math so the last execution of that http string, contains the < 5 amount and then I am done.
Trying to wrap my head around the logic needed using either ForEach or Do loops and getting a headache.
Anyone have sample code they would be willing to share that could be me a good starting point?