< Back
Get-Chunk
Post
NAME Get-Chunk
SYNOPSIS
Splits an array into arrays each not exceeding the given size.
SYNTAX
Get-Chunk [[-size] <Int32>] [-InputObject <Object>] [<CommonParameters>]
DESCRIPTION
The native Powershell cmdlet Get-Chunk splits an array into arrays each not exceeding the given size.
The cmdlet preserve or reverse the order of elements depending on the sign of the parameter size.
PARAMETERS
-size <Int32>
An integer specifies the maximum size of a chunk. The last chunk may be smaller.
If size > 0 then the order of the elements is preserved.
If size < 0 then the order of the elements is reversed.
If size = 0 then the cmdlet Get-Chunk returns one array contains all input objects.
Required? false
Position? 1
Default value 1
Accept pipeline input? false
Accept wildcard characters? false
-InputObject <Object>
Specifies the objects to chunked.
Required? false
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
You can pipe the objects to be chunked to Get-Chunk.
OUTPUTS
Get-Chunk returns the array of arrays.
NOTES
With a positive chunk size the cmdlet Get-Chunks sends chunks to the pipe as soon as the chunk is filled.
Otherwise the cmdlet collect all input objects, splits it into chunks and then sends the chunks to the pipe.
-------------------------- EXAMPLE 1 --------------------------
PS>'a','b','c','d','e' | Get-Chunk 2
Returns an array of arrays whose length does not exceed 2
Expected result is @( @('a','b'), @('c','d'), @('e') )
-------------------------- EXAMPLE 2 --------------------------
PS>Get-Chunk -3 -InputObject @(1,2,3,4,5,6,7,8)
Returns an array of arrays whose length does not exceed 3 and their elements are in reverse order
Expected result is @( @(8,7,6), @(5,4,3), @(2,1) )
RELATED LINKS
https://github.com/mazzy-ax/Powershell.Chunks
SYNOPSIS
Splits an array into arrays each not exceeding the given size.
SYNTAX
Get-Chunk [[-size] <Int32>] [-InputObject <Object>] [<CommonParameters>]
DESCRIPTION
The native Powershell cmdlet Get-Chunk splits an array into arrays each not exceeding the given size.
The cmdlet preserve or reverse the order of elements depending on the sign of the parameter size.
PARAMETERS
-size <Int32>
An integer specifies the maximum size of a chunk. The last chunk may be smaller.
If size > 0 then the order of the elements is preserved.
If size < 0 then the order of the elements is reversed.
If size = 0 then the cmdlet Get-Chunk returns one array contains all input objects.
Required? false
Position? 1
Default value 1
Accept pipeline input? false
Accept wildcard characters? false
-InputObject <Object>
Specifies the objects to chunked.
Required? false
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
You can pipe the objects to be chunked to Get-Chunk.
OUTPUTS
Get-Chunk returns the array of arrays.
NOTES
With a positive chunk size the cmdlet Get-Chunks sends chunks to the pipe as soon as the chunk is filled.
Otherwise the cmdlet collect all input objects, splits it into chunks and then sends the chunks to the pipe.
-------------------------- EXAMPLE 1 --------------------------
PS>'a','b','c','d','e' | Get-Chunk 2
Returns an array of arrays whose length does not exceed 2
Expected result is @( @('a','b'), @('c','d'), @('e') )
-------------------------- EXAMPLE 2 --------------------------
PS>Get-Chunk -3 -InputObject @(1,2,3,4,5,6,7,8)
Returns an array of arrays whose length does not exceed 3 and their elements are in reverse order
Expected result is @( @(8,7,6), @(5,4,3), @(2,1) )
RELATED LINKS
https://github.com/mazzy-ax/Powershell.Chunks