Split-Array
PowerShell moduleSequential processing of large data sets can take a long time — especially with cloud APIs. The answer is parallelisation, and for that the data first has to be split into portions (chunks).
So this wheel isn't reinvented in every script, Split-Array takes care of exactly this step: it splits an array into an array of arrays — either by maximum chunk size or into a fixed number of chunks.
Small but neat: edge cases are handled, and input works both as an argument and via the pipeline.
Installation
The module is cloned from the repository and imported via its manifest:
git clone https://github.com/kreisi-dev/Split-Array SplitArray
Import-Module ./SplitArray/SplitArray.psd1 PowerShell 5.1 or newer is required. For permanent availability, copy the SplitArray folder into one of your $env:PSModulePath directories and import it by name.
Usage examples
1. Split by maximum chunk size (-ChunkSize)
Defines the maximum number of elements allowed in a sub-array. Ideal for API batches.
# Greedy distribution (default): fills chunks to the maximum
Split-Array -InputObject 1..10 -ChunkSize 3
# Result: (1,2,3), (4,5,6), (7,8,9), (10)
# Even distribution: spreads the remainder evenly
Split-Array -InputObject 1..10 -ChunkSize 3 -Distribution Even
# Result: (1,2,3), (4,5,6), (7,8), (9,10) 2. Split into exactly N chunks (-MaxChunk)
Splits the array into a fixed number of chunks.
# Even distribution (default): produces exactly 4 balanced chunks
Split-Array -InputObject 1..10 -MaxChunk 4
# Result: (1,2,3), (4,5,6), (7,8), (9,10) 3. Pad the last chunk (-Pad)
Fills the last chunk with a value until it matches the size of the first chunk — useful when downstream code expects equally sized chunks.
# Pad with $null up to the full chunk size
Split-Array -InputObject 1..10 -ChunkSize 3 -Pad $null
# Result: (1,2,3), (4,5,6), (7,8,9), (10,$null,$null) Distribution strategies
| Strategy | Behaviour | Default for |
|---|---|---|
Greedy | Fills each chunk to the maximum; the last chunk takes the remaining elements. | -ChunkSize |
Even | Spreads the remainder element by element across the first chunks; always produces exactly the requested number of chunks. | -MaxChunk |
Parameters
| Parameter | Function |
|---|---|
InputObject | The array or elements to split. Accepts pipeline input. |
ChunkSize | Maximum number of elements per chunk. Mutually exclusive with -MaxChunk. |
MaxChunk | Desired number of output chunks. Mutually exclusive with -ChunkSize. |
Distribution | Distribution strategy Greedy or Even — controls how the remainder is placed. |
Pad | Value used to fill the last chunk to a uniform size (e.g. $null, 0, "x"). |