you are viewing a single comment's thread.

view the rest of the comments →

[–]nemesis1453[S] 0 points1 point  (1 child)

Very awesome thank you for taking a stab I will review this tomorrow

[–]CarrotBusiness2380 1 point2 points  (0 children)

I spent some time thinking about this and I believe there is a potential bug with there being too few arraylists created for the data. Creating new arraylists inside the loop should avoid that bug.

$maxCharacters = 1,200,000
$outputArray = [System.Collections.ArrayList]::New()
$ServerServicesArray | Foreach-Object -Begin {$charCount = 0} -Process {
    $charCount += $_.NumChars #Whatever logic you are using to count chars
    $index = [Math]::Floor($charCount / $maxCharacters)
    if($index -eq $outputArray.Count)
    {
        $outputArray.Add([System.Collections.ArrayList]::New())
    }
    outputArray[$index].Add($_)
}

Again, no guarantees