1

I have a Powershell script that retrieves some data from a database, uses Group-Object to collect it into similar groups, then uses foreach to act on each group.

The trouble is that some groups have more than 100 items, but my process can only act on 100 at once. It was written specifically to handle the items in the Group-Object results and I'd rather not rewrite that part.

Is there some elegant way to have Group-Object break up the groups into at most 100 items at a time? Or do I have to collect them with a for loop?

1 Answer 1

1

Here's what I came up with, partially thanks to this answer:

# create hashtable with unique basedomain as key and zero as value $NameHash = @{}; foreach ($i in $tbl.rows | Group-Object basedomain) { $NameHash[$i.Name]=0; } # regroup using the hashtable as a counter source $result = $tbl.rows | Group-Object basedomain, { [math]::Floor($NameHash[$_.basedomain]++ / 100) } 
1
  • Actually, I simplified it further. Now the SQL that generates the data will itself use a hash function to put the members into bins. Commented Oct 29, 2017 at 3:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.