-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To split object into requires groupnumber
- Loading branch information
1 parent
d01be9e
commit 7095073
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
$numbers = 1..131 | ||
$GroupNum = 20 | ||
$skipcount = [math]::Truncate($numbers.count / $GroupNum) | ||
|
||
0..$skipcount | %{ | ||
$numbers | Select-Object -skip $($GroupNum*$_) -First $GroupNum | ||
"--------------------------------------------" | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function Split-Object{ | ||
|
||
[CmdletBinding( | ||
SupportsShouldProcess = $false, | ||
ConfirmImpact = "none", | ||
DefaultParameterSetName = "" | ||
)] | ||
|
||
param | ||
( | ||
[Parameter( | ||
HelpMessage = "Input Object you want to split", | ||
Position = 0, | ||
Mandatory = $false, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
#[ValidateNotNullOrEmpty()] | ||
[object[]] | ||
$Item, | ||
|
||
[Parameter( | ||
HelpMessage = "Input Number you want to split each", | ||
Position = 0, | ||
Mandatory = $false, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[ValidateNotNullOrEmpty()] | ||
[int] | ||
$GroupNumber | ||
) | ||
|
||
begin | ||
{ | ||
$skipcount = [math]::Truncate($Item.count / $GroupNumber) | ||
} | ||
|
||
process | ||
{ | ||
|
||
0..$skipcount | %{ | ||
$Item | Select-Object -skip $($GroupNumber * $_) -First $GroupNumber | ||
# {Set command you want to do...} | ||
} | ||
} | ||
|
||
end | ||
{ | ||
} | ||
} | ||
|
||
Split-Object -Item $(ps | sort WS -Descending) -GroupNumber 20 |